Backup mysql database with php and zip it

By | May 1, 2009

Many php applications prefer to backup the mysql database from within the application and save it as an archive. The mysqldump commandline utility can be used to perform this function of backing up a mysql database as sql file. The command would be like this : mysqldump –user=$username –password=$password –opt $db_name > $dir/backup.sql The above… Read More »

Php – parse text and convert urls into hyperlinks

By | May 10, 2020

The following function will parse a given text and convert all the urls into links. It does this using regular expressions. It converts email addresses to mailto links as well. Code function parse_links($str) { $str = str_replace('www.', 'http://www.', $str); $str = preg_replace('|http://([a-zA-Z0-9-./]+)|', '<a href="http://$1">$1</a>', $str); $str = preg_replace('/(([a-z0-9+_-]+)(.[a-z0-9+_-]+)*@([a-z0-9-]+.)+[a-z]{2,6})/', '<a href="mailto:$1">$1</a>', $str); return $str; }

Install Postgresql, phpPgAdmin and pgadmin on Ubuntu

By | March 25, 2009

Install Postgresql , phpPGAdmin and pgadmin 3 can be installed from synaptic. $ sudo apt-get install postgresql phppgadmin pgadmin3 After installation some configuration needs to be done. First of all setup the password of the user ‘postgres’ which is the default user of postgresql. Type the following in the terminal $ sudo -u postgres psql… Read More »

Run php scripts from cron

By | March 22, 2009

Automatic Running In a web application there are many cases, when a certain piece of code or script needs to run automatically in the background to perform certain tasks, without the need of any user to start it. Like scraping, extracting or crawling data from web or perform some regular tasks like sending emails, system… Read More »

How to Install Apache Mod Rewrite on Ubuntu / Linux

By | August 8, 2020

Apache Mod Rewrite mod_rewrite is an apache module which enables rewriting of urls requested by client before the pages are fetched by apache. For example www.site.com/products.php?code=459 can be written as www.site.com/products/459 or www.site.com/products/459.html. The second url is re-written into the first one by mod_rewrite using rewrite rules specified in the .htaccess file. Enable Mod Rewrite… Read More »

Get real IP address of user in php

By | December 4, 2008

Client IP address Php applications are mostly web based and often need to get the ip address of the user who is connecting to the application. Ip address is required for various logging purpose, geolocation service etc. The most common way to get the ip address of a remote user is by using the superglobal… Read More »