Sunday, July 21, 2013

Decompress/Unzip Web Content with Content-Encoding: gzip (using PHP - file_get_contents() and gzinflate())

If you are using file_get_contents() to grab content from the web and process using PHP, you may bump into web contents that are compressed using gzencode. Here's a solution to decompress those content (simplified for easy reference): <?php $qdata = array('http' =>     array(      'method' => 'POST',      'user_agent'=> $_SERVER['HTTP_USER_AGENT']     )    ); ...
Read More »

Compress External Javascript with gzip in PHP

If you are using an external Javascript, you can compress the content before sending it to the browser using PHP. Here's the solution (simplified for easy reference): <?php error_reporting(0); // make sure it is not reporting any warning that will ruin the output $js = <<<MYJAVASCRIPT . . . MYJAVASCRIPT; // Optional: The following three lines of extra codes are to downsize...
Read More »

Saturday, July 20, 2013

Javascript to Dynamically Change the Image Source of an Element for IE

Just like the problem of changing background color for IE via Javascript, changing the image source requires special treatment as well. Here's the solution (simplified for easy reference): Javascript: var ie = (navigator.userAgent.indexOf("MSIE") != -1); if (!ie) {    document.getElementById('MyImageID').src = 'myImageSrcName.jpg'; } else {    document.getElementById('MyElemID').innerHTML = '<img src="myImageSrcName.jpg">'; } HTML: <span...
Read More »

Javascript to Dynamically Change the Background Color of an Element for IE

You can change the background color easily in Chrome, Safari and Firefox. But for IE, you cannot change it using the easy way like the other browsers are doing it. Here's the solution (simplified for easy reference): var ie = (navigator.userAgent.indexOf("MSIE") != -1); if (!ie) {    document.getElementById('MyElemID').style.backgroundColor = "#AABBCC"; } else {    document.getElementById('MyElemID').style.backgroundColor = "rgb('AA','BB','CC')"; } Therefore,...
Read More »