Short Tag – Web Development Blog

Entries for April 20th, 2010

htmlspecialchars_decode for PHP4

Sometimes we do not have all the things we want on a webserver and on shared hosting we cannot do much about it, so we find workarounds. This is the equivalent of the htmlspecialchars_decode function in PHP4. htmlspecialchars_decode is available only from PHP5, so this little function of mine can be quite handy on PHP4.

if [...]

Unzip with PHP

To unzip with PHP you need to have your PHP server compiled with php_zip.dll on Linux or the php_zip.dll extension active on Windows(activate it from php.ini).

$zip = zip_open("");
//first we open the zip file, $zip is a file handler

if ($zip) {
while ($zip_entry = zip_read($zip)) {
//reading each zip entry (zip file)

$fp = fopen("zip/".zip_entry_name($zip_entry), "w");
//open the file for [...]

getElementsByClassName in Javascript

This is a function that returns all the elements in the page that have the given class name.
Returns an array with the objects.

function getElementsByClassName( strClassName, obj ) {
var ar = arguments[2] || new Array();
var re = new RegExp("\\b" + strClassName + "\\b", "g");

if ( re.test(obj.className) ) {
ar.push( obj );
for ( var i = 0; i [...]

Set cookie with javascript

Sometimes is useful to set a cookie with javascript. You can use the function below.

function Set_Cookie(name, value, expires, path, domain, secure )
var today = new Date();
today.setTime( today.getTime() );

if ( expires ) { expires = expires * 1000 * 60 * 60 * 24; }
var expires_date = new Date( today.getTime() + (expires) );
document.cookie = name + [...]