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']
)
);
...
Sunday, July 21, 2013
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...
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...
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,...
Subscribe to:
Posts (Atom)