search
top

Extracting String

This is small but very useful script. I have shown example for extracting only ‘src’ value from the ‘img’ tag, but you can modify and use as per your requirement using ‘preg_match_all’ function. <?php $src= '<img height="120" width="120" border="0" src="http://www.somesite.com/abc.jpg" class="image"/>'; preg_match_all('/(src)=("[^"]*")/i',$src,...
read more

Page Redirect

I have written a script for getting the files list from directory and redirecting the page on selecting option from the select box. So you will get the script for fetching all the files from current directory and redirecting page on selection. <h>Please select option</h> <?php $path = $_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI']; //current directory physical path $dir_handle...
read more

Database Backup

I am listing here the PHP script to generate backup of database. <?php /* Database Backup */ $username = "dbusername"; //database username $password = 'dbpass'; //database password $hostname = "localhost"; //host $dbname = "dbname"; //databse name $sConnString = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $name...
read more

Get IP Address in PHP

Many times we need the IP Address of the User visiting our website in our Application. I am listing here the method to get the User IP Address, hope it might be useful to many of you. //function for getting IP //start function getuserip() { if (isset($_SERVER)) { if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) return $_SERVER["HTTP_X_FORWARDED_FOR"]; ...
read more

Assign PHP Array to Javascript Array

I am describing here a very useful method for getting the values of a PHP array in JavaScript. For this we need to assign the PHP array values to a array in JavaScript. <?php $a = array('A','B','C'); ?> <html> <head> <title>Assign PHP Array to Javascript Array</title> <script language="javascript"> function showValues(){ var a=new Array; <?php for($i=0;$i<count($a);...
read more

Copy Directory

I am listing here the method to copy full Directories with all sub-directories and files. <?php $source = 'f1'; //folder name $target = 'f2'; //folder name , if target folder does not exists, it will be created //echo 'src->'.$source.'<br/>'; //echo 'tar->'.$target.'<br/>'; if(is_dir($source)) { full_copy($source,$target); echo 'Folder copied'; } else { echo...
read more

Display numeric in words

I hope this script will be very useful to all of you who are working in PHP. Actually this is a kind of small and useful project. I was asked to develop a script for displaying sum total in words in one of my interviews, at that time I could not complete this script. So I decided to complete it, and so I developed it, which I am sharing with you all. This script can display numeric to words upto millions...
read more

encode and decode string with base64

Many use encoding and decoding on daily basis including me, so once I made a simple script for encoding and decoding the input string with base64. base64.txt Instruction: 1) Download the file and save the text file as PHP file. 2) Place the file in your root directory. 3) Execute the file from browser. 4) Enter the string to and decode or encode it by selecting the options.
read more

Generate XML

XML files are used for various functionalities. We can develop XML files by using PHP. If you have to develop very small project, you can use XML files for saving data instead of MySQL or any other databse with PHP, which will be easy for maintaining and response time will be reduced. I am listing a simple example. <?php $doc = new DOMDocument(); $doc->formatOutput = true; //$p...
read more

ASCII example

You might have visited many sites related to songs or movies, you might have noticed that the searching is in Alphabetical order, so what will you do if you want such listing, write all the characters from A to Z ?. There is an easy way for implementing this in PHP. We can use function ord() and chr(). ord – Return ASCII value of character. chr – Return a specific character. I am attaching a simple...
read more

« Previous Entries Next Entries »

top