开发者

String compression in PHP and JavaScript

开发者 https://www.devze.com 2023-02-16 22:20 出处:网络
Is there a way I can compress a long string (e.g. a long JSON string) in PHP and then decompress it in JavaSc开发者_高级运维ript?A solution would be to use gzip compression of the whole output of your

Is there a way I can compress a long string (e.g. a long JSON string) in PHP and then decompress it in JavaSc开发者_高级运维ript?


A solution would be to use gzip compression of the whole output of your PHP script -- and to let the browser handle the decompression, on the client-side.

If you are working with Apache, you can use mod_deflate.
Else, in PHP, you can use ob_gzhandler -- see the example on that manual page.

Then, on the client-side (browser), you have nothing to do : the decompression will be dealt with automatically.


As a sidenote : using mod_deflate, you can configure so CSS, Javascript, HTML (well, all data that are text) are compressed the same way -- which will reduce the size of your pages, and speed up their loading a bit ; so, it's worth investigating a bit ;-)


  <?php
     $str1 = "Test";
     $str2 = "Test";
     if ($str1 == "Test") echo "OK-1";
     if ($str1 == $str2) echo "OK-2";
  ?>


function isSameString( s1, s2 )
  {
    alert( "s1: " + s1.toString() );
    alert( "s2: " + s2.toString() );

    return s1.toString() == s2.toString();
  }
0

精彩评论

暂无评论...
验证码 换一张
取 消