Category Archives: Coding

All kinds of Programming.

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; }

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 »

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 »

Execute an sql script in jdbc

By | April 4, 2008

The SQL Script should have comments starting with – or — only on new lines and each command should end with a ; . Reading a sql file and putting all of it in a string variable and feeding to the execute command would result in an exception. All instructions must be executed individually. A… Read More »

Read write and save configurations to a file in java

By | April 2, 2008

Configuration files are used in applications to store settings, user preferences and other configuration parameters of an application so that. When configurations are changed from within the application these need to be saved so that next time the application starts with these new settings. In Java reading and writing to a configuration is pretty simple… Read More »