setAttribute/getAttribute(“style”) crossbrowser alternative

The JavaScript methods setAttribute and getAttribute are very handy when you are designing dynamic effects for your website, but those methods have a lot of bugs in IE (6 an 7 at least), I use these two crossbrowser functions as alternatives instead of using directly setAttribute() and getAttribute(), I’ve been using them for quite a [...]

How to upgrade Ubuntu from 8.10 to 9.04 using the command line and the Internet?

You can upgrade your linux system using the package manager APT which is available on debian based distributions: First we have to update all the packages installed: $ sudo apt-get update $ sudo apt-get upgrade Now we make sure that we have the update-manager-core package installed with: sudo apt-get install update-manager-core Then we start the [...]

How to check a file type efficiently in PHP?

The Problem Do you know a method in PHP to check the type of an uploaded file without relying on extension or Mime-type because these two can be faked? Verifying the file type in PHP Relying on the Mime-type of a file submitted by a user is a bad practice, using the extension is even [...]

Print HTML code from JavaScript variable

This also was about to drive me crazy so I will not let it go without writing about it.. Let’s say you have some long HTML code contained on a PHP variable, something like this <?php # define the $html variable using the # Nowdoc syntax to avoid parsing $html = <<<’HTML’ <div id=”box”> <h1>Title</h1> [...]

A note on JavaScript arrays creation & initialization

I use PHP a lot in my projects and it happens that sometimes I combine PHP with another language and write completely useless code. PHP arrays can be created and initialized with like this: <?php $cities[] = “mecca”; $cities[] = “medina”; ?> I thought that the same would apply to javascript… Yes, it can work, [...]

Get file extension on PHP

There are many ways to retrieve files extension with PHP, but we will have to choose one that feets our needs and gives more reliable results. When dealing with file extension you should know that a file extension is not always 3 characters long (ex:  foto.jpeg, index.html) and that it doesn’t start after the last [...]

Install PHP 5.2.6 on CentOs 5.x

Oddly enough, PHP 5.2.6 is still not available on default CentOS repositories ([base], [updates], [addons], and [extras]), latest PHP available in those repos is PHP 5.1.6! In order to install PHP 5.2.6 you can add the CentOS testing repository and enable it then install or update PHP. To add the CentOS testing directory, create a [...]

Smarty error: Warning: preg_match() [function.preg-match]: Compilation failed: repeated subpattern is too long at offset 18454 in …

Warning: preg_match() [function.preg-match]: Compilation failed: repeated subpattern is too long at offset 18454 in /var/www/html/[...]/Smarty/Smarty_Compiler.class.php on line 454 It looks that you are running an old version of Smarty, latest version as I write is 2.6.26, you can download it from here.

MySQL script files tutorial for beginners

What is a MySQL script file?.. Why use it? A MySQL script file (aka MySQL batch file) is a regular text file containing MySQL statements separeted by terminantors, statements in a MySQL script file can be executed from the MySQL client, this is very useful, many PHP script available online come with MySQL script files [...]

How to read .chm files in Ubuntu

xchm installation

This tutorial assumes that you are a sudoer running Gnome What is .chm Wikipedia says: Microsoft Compiled HTML Help is a proprietary format for online help files, developed by Microsoft and first released in 1997 as a successor to the Microsoft WinHelp format. It was first introduced with the release of Windows 98, and is [...]