<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4357119732797762613</id><updated>2012-01-28T11:09:06.779-08:00</updated><category term='Simple function to read directory contents'/><category term='Format USA phone number'/><category term='php preperation'/><category term='spell checker in php'/><category term='Format File Size in php'/><category term='php interviews'/><category term='perg_replace technique'/><category term='soundex function in php'/><category term='required() and include()'/><category term='Resize Image in PHP'/><category term='Format US phone number'/><category term='Compressing Zip file in PHP'/><category term='Format date'/><category term='soundex function'/><category term='Convert Hex to String in php'/><category term='interview preperation'/><category term='Use the soundex() function to test if words sound similar'/><category term='date format'/><category term='php date format'/><category term='convert string to hex in php'/><category term='Format File Size'/><category term='PHP interview questions'/><category term='Resize Image'/><category term='required and include'/><category term='php text spell checker'/><category term='date format php'/><category term='Get the list of folders and/or Files'/><category term='add days'/><category term='php add days'/><category term='How to use the similar_text function  to compare similar words'/><category term='SQL date format'/><category term='Make String usable as a URI'/><category term='php interview'/><category term='image resize'/><category term='Convert String to Hex'/><category term='convert into sql date foramt'/><category term='Shows how to use the build-in function &quot;wordwrap&quot; to create line breaks by a user definied length.'/><category term='Convert Hex to String'/><category term='How to Strip file Extension'/><category term='Get the list of folders and/or Files in php'/><category term='similar_text function in php'/><category term='php spell checker'/><category term='php Convert Hex to String'/><category term='Difference Between require and include'/><category term='add days to current date'/><category term='Checks whether $string begins with $search'/><title type='text'>PHP Scripts, User Based Scripts, Link Based Scripts, URL Based Scripts, Form Based Scripts</title><subtitle type='html'>PHP Scripts, phpBB, PDF Scripts, Download Scripts,  PayPal Scripts, Quote Scripts, Catalog Scripts, Billing System Scripts, Credit Card Scripts, Miscellaneous, Barcode Scripts, Utility Scripts, Performance Software, Miscellaneous, Environment Scripts, Libraries and Classes, Debugging Scripts, Bug Tracking Software, Application Framework, Live Support Scripts, Help Desk Software, Personals Scripts, Real Estate Software,Postcard Scripts, Guestbook Scripts, Graph and Chart Scripts</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>88</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-7596217720444573143</id><published>2009-05-25T11:03:00.003-07:00</published><updated>2009-05-25T11:03:54.151-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Resize Image in PHP'/><category scheme='http://www.blogger.com/atom/ns#' term='image resize'/><category scheme='http://www.blogger.com/atom/ns#' term='Resize Image'/><title type='text'>Resize Image in PHP</title><content type='html'>&lt;?php&lt;br /&gt;&lt;br /&gt;function resize_jpg($inputFilename, $new_side){&lt;br /&gt;        $imagedata = getimagesize($inputFilename);&lt;br /&gt;        $w = $imagedata[0];&lt;br /&gt;        $h = $imagedata[1];&lt;br /&gt;&lt;br /&gt;        if ($h &gt; $w) {&lt;br /&gt;                $new_w = ($new_side / $h) * $w;&lt;br /&gt;                $new_h = $new_side;&lt;br /&gt;        } else {&lt;br /&gt;                $new_h = ($new_side / $w) * $h;&lt;br /&gt;                $new_w = $new_side;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        $im2 = ImageCreateTrueColor($new_w, $new_h);&lt;br /&gt;        $image = ImageCreateFromJpeg($inputFilename);&lt;br /&gt;        imagecopyResampled ($im2, $image, 0, 0, 0, 0, $new_w, $new_h, $imagedata[0], $imagedata[1]);&lt;br /&gt;        return $im2;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-7596217720444573143?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/7596217720444573143/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=7596217720444573143' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/7596217720444573143'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/7596217720444573143'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2009/05/resize-image-in-php.html' title='Resize Image in PHP'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-7590802158379957739</id><published>2009-05-25T11:03:00.001-07:00</published><updated>2009-05-25T11:03:18.814-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Format File Size in php'/><category scheme='http://www.blogger.com/atom/ns#' term='Format File Size'/><title type='text'>Format File Size</title><content type='html'>&lt;?php&lt;br /&gt;        function GetFileSize($nBytes)&lt;br /&gt;        {&lt;br /&gt;                if ($nBytes &gt;= pow(2,40))&lt;br /&gt;                {&lt;br /&gt;                        $strReturn = round($nBytes / pow(1024,4), 2);&lt;br /&gt;                        $strSuffix = "TB";&lt;br /&gt;                }&lt;br /&gt;                elseif ($nBytes &gt;= pow(2,30))&lt;br /&gt;                {&lt;br /&gt;                        $strReturn = round($nBytes / pow(1024,3), 2);&lt;br /&gt;                        $strSuffix = "GB";&lt;br /&gt;                }&lt;br /&gt;                elseif ($nBytes &gt;= pow(2,20))&lt;br /&gt;                {&lt;br /&gt;                        $strReturn = round($nBytes / pow(1024,2), 2);&lt;br /&gt;                        $strSuffix = "MB";&lt;br /&gt;                }&lt;br /&gt;                elseif ($nBytes &gt;= pow(2,10))&lt;br /&gt;                {&lt;br /&gt;                        $strReturn = round($nBytes / pow(1024,1), 2);&lt;br /&gt;                        $strSuffix = "KB";&lt;br /&gt;                }&lt;br /&gt;                else&lt;br /&gt;                {&lt;br /&gt;                        $strReturn = $nBytes;&lt;br /&gt;                        $strSuffix = "Byte";&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                if ($strReturn == 1)&lt;br /&gt;                {&lt;br /&gt;                        $strReturn .= " " . $strSuffix;&lt;br /&gt;                }&lt;br /&gt;                else&lt;br /&gt;                {&lt;br /&gt;                        $strReturn .= " " . $strSuffix . "s";&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                return $strReturn;&lt;br /&gt;        }&lt;br /&gt;?&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-7590802158379957739?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/7590802158379957739/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=7590802158379957739' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/7590802158379957739'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/7590802158379957739'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2009/05/format-file-size.html' title='Format File Size'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-6057637432899090518</id><published>2009-05-25T11:02:00.003-07:00</published><updated>2009-05-25T11:02:59.828-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Get the list of folders and/or Files'/><category scheme='http://www.blogger.com/atom/ns#' term='Get the list of folders and/or Files in php'/><title type='text'>Get the list of folders and/or Files</title><content type='html'>&lt;?php&lt;br /&gt;&lt;br /&gt;  function listFolder($folder, $types = 0)&lt;br /&gt;  {&lt;br /&gt;    $functions = array(&lt;br /&gt;        1 =&gt; 'is_dir',&lt;br /&gt;        2 =&gt; 'is_file'&lt;br /&gt;      );&lt;br /&gt;&lt;br /&gt;    $folderList = array();&lt;br /&gt;&lt;br /&gt;    foreach( glob( "$folder/*" ) as $currentItem )&lt;br /&gt;    {&lt;br /&gt;      if( $types == 1 or $types == 2 )&lt;br /&gt;      {&lt;br /&gt;        if( $functions[$types]($currentItem) )&lt;br /&gt;          $folderList[] = basename($currentItem);&lt;br /&gt;      }&lt;br /&gt;      else $folderList[] = basename($currentItem);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    return $folderList;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;?&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-6057637432899090518?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/6057637432899090518/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=6057637432899090518' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/6057637432899090518'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/6057637432899090518'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2009/05/get-list-of-folders-andor-files.html' title='Get the list of folders and/or Files'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-9076948132360821988</id><published>2009-05-25T11:02:00.001-07:00</published><updated>2009-05-25T11:02:24.726-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='How to Strip file Extension'/><title type='text'>How to Strip file Extension</title><content type='html'>&lt;?php&lt;br /&gt;        function strip_ext($name)&lt;br /&gt;        {&lt;br /&gt;                $ext = strrchr($name, '.');&lt;br /&gt;&lt;br /&gt;                if($ext !== false)&lt;br /&gt;                {&lt;br /&gt;                        $name = substr($name, 0, -strlen($ext));&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                return $name;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        // demonstration&lt;br /&gt;        $filename = 'file_name.txt';&lt;br /&gt;        echo strip_ext($filename)."n";&lt;br /&gt;&lt;br /&gt;        // to get the file extension, do&lt;br /&gt;        echo end(explode('.',$filename))."n";&lt;br /&gt;?&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-9076948132360821988?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/9076948132360821988/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=9076948132360821988' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/9076948132360821988'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/9076948132360821988'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2009/05/how-to-strip-file-extension.html' title='How to Strip file Extension'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-5841267646146413291</id><published>2009-05-25T11:01:00.003-07:00</published><updated>2009-05-25T11:01:59.067-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Simple function to read directory contents'/><title type='text'>Simple function to read directory contents</title><content type='html'>&lt;?php&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;** Function: dir_list (PHP)&lt;br /&gt;** Desc: Simple function to read directory contents&lt;br /&gt;** Example: dir_list('data/');&lt;br /&gt;** Author: Jonas John&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;function dir_list($path){&lt;br /&gt;&lt;br /&gt;    $files = array();&lt;br /&gt;&lt;br /&gt;    if (is_dir($path)){&lt;br /&gt;        $handle = opendir($path);&lt;br /&gt;        while ($file = readdir($handle)) {&lt;br /&gt;            if ($file[0] == '.'){ continue; }&lt;br /&gt;&lt;br /&gt;            if (is_file($path.$file)){&lt;br /&gt;                $files[] = $file;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        closedir($handle);&lt;br /&gt;        sort($files);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    return $files;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;?&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-5841267646146413291?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/5841267646146413291/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=5841267646146413291' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/5841267646146413291'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/5841267646146413291'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2009/05/simple-function-to-read-directory.html' title='Simple function to read directory contents'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-1281140468908403301</id><published>2009-05-25T11:01:00.001-07:00</published><updated>2009-05-25T11:01:20.653-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Compressing Zip file in PHP'/><title type='text'>Compressing Zip file in PHP</title><content type='html'>&lt;?php&lt;br /&gt;&lt;br /&gt;function compress_handler($in_output)&lt;br /&gt;{&lt;br /&gt;  return gzencode($in_output);&lt;br /&gt;}&lt;br /&gt;if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'],'gzip') !== FALSE)&lt;br /&gt;{&lt;br /&gt;  ob_start('compress_handler');&lt;br /&gt;  header('Content-Encoding: gzip');&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;  ob_start();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-1281140468908403301?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/1281140468908403301/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=1281140468908403301' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/1281140468908403301'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/1281140468908403301'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2009/05/compressing-zip-file-in-php.html' title='Compressing Zip file in PHP'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-700831176683596478</id><published>2009-05-25T11:00:00.003-07:00</published><updated>2009-05-25T11:00:54.231-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Format USA phone number'/><category scheme='http://www.blogger.com/atom/ns#' term='Format US phone number'/><title type='text'>Format US phone number</title><content type='html'>&lt;?php&lt;br /&gt;  // Format US phone number&lt;br /&gt;  function formatPhoneNumber($strPhone)&lt;br /&gt;  {&lt;br /&gt;          $strPhone = ereg_replace("[^0-9]",'', $strPhone);&lt;br /&gt;          if (strlen($strPhone) != 10)&lt;br /&gt;          {&lt;br /&gt;                  return $strPhone;&lt;br /&gt;          }&lt;br /&gt;&lt;br /&gt;          $strArea = substr($strPhone, 0, 3);&lt;br /&gt;          $strPrefix = substr($strPhone, 3, 3);&lt;br /&gt;          $strNumber = substr($strPhone, 6, 4);&lt;br /&gt;&lt;br /&gt;          $strPhone = "(".$strArea.") ".$strPrefix."-".$strNumber;&lt;br /&gt;&lt;br /&gt;          return ($strPhone);&lt;br /&gt;  }&lt;br /&gt;?&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-700831176683596478?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/700831176683596478/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=700831176683596478' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/700831176683596478'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/700831176683596478'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2009/05/format-us-phone-number.html' title='Format US phone number'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-5345070624995143013</id><published>2009-05-25T11:00:00.001-07:00</published><updated>2009-05-25T11:00:29.045-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Shows how to use the build-in function &quot;wordwrap&quot; to create line breaks by a user definied length.'/><title type='text'>Shows how to use the build-in function "wordwrap" to create line breaks by a user definied length.</title><content type='html'>&lt;?php&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;** Function: wordwrap example (PHP)&lt;br /&gt;** Desc: Shows how to use the build-in function "wordwrap" to create line breaks by a user definied length.&lt;br /&gt;** Example: see below&lt;br /&gt;** Author: Jonas John&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;// create a long text for testing:&lt;br /&gt;$long_text = 'This is a long text to demonstrate the usage of the ';&lt;br /&gt;$long_text .= 'wordwrap function. ';&lt;br /&gt;$long_text .= 'Fooooooooooooooooobar, just fooling around';&lt;br /&gt;&lt;br /&gt;// syntax: wordwrap(input string, line max. width, break chars, cut words)&lt;br /&gt;$new_text = wordwrap($long_text, 15, "&lt;br/&gt;\n", true);&lt;br /&gt;&lt;br /&gt;print $new_text;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;The output will be:&lt;br /&gt;&lt;br /&gt;This is a long&lt;br/&gt;&lt;br /&gt;text to&lt;br/&gt;&lt;br /&gt;demonstrate the&lt;br/&gt;&lt;br /&gt;usage of the&lt;br/&gt;&lt;br /&gt;wordwrap&lt;br/&gt;&lt;br /&gt;function.&lt;br/&gt;&lt;br /&gt;Foooooooooooooo&lt;br/&gt;&lt;br /&gt;ooobar, just&lt;br/&gt;&lt;br /&gt;fooling around&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;?&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-5345070624995143013?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/5345070624995143013/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=5345070624995143013' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/5345070624995143013'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/5345070624995143013'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2009/05/shows-how-to-use-build-in-function.html' title='Shows how to use the build-in function &quot;wordwrap&quot; to create line breaks by a user definied length.'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-821483336045471362</id><published>2009-05-25T10:59:00.001-07:00</published><updated>2009-05-25T10:59:58.386-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='How to use the similar_text function  to compare similar words'/><category scheme='http://www.blogger.com/atom/ns#' term='similar_text function in php'/><title type='text'>How to use the similar_text function  to compare similar words</title><content type='html'>&lt;?php&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;** Function: similar_text (PHP)&lt;br /&gt;** Desc: Shows how to use the similar_text() function to compare similar words.It returns how similar the words are.&lt;br /&gt;** Example: see below&lt;br /&gt;** Author: Jonas John&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;$word2compare = "stupid";&lt;br /&gt;&lt;br /&gt;$words = array(&lt;br /&gt;    'stupid',&lt;br /&gt;    'stu and pid',&lt;br /&gt;    'hello',&lt;br /&gt;    'foobar',&lt;br /&gt;    'stpid',&lt;br /&gt;    'upid',&lt;br /&gt;    'stuuupid',&lt;br /&gt;    'sstuuupiiid',&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;while(list($id, $str) = each($words))&lt;br /&gt;{&lt;br /&gt;    similar_text($str, $word2compare, $percent);&lt;br /&gt;&lt;br /&gt;    print "Comparing '$word2compare' with '$str': ";&lt;br /&gt;    print round($percent) . "%\n";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;Results:&lt;br /&gt;&lt;br /&gt;Comparing 'stupid' with 'stupid': 100%&lt;br /&gt;Comparing 'stupid' with 'stu and pid': 71%&lt;br /&gt;Comparing 'stupid' with 'hello': 0%&lt;br /&gt;Comparing 'stupid' with 'foobar': 0%&lt;br /&gt;Comparing 'stupid' with 'stpid': 91%&lt;br /&gt;Comparing 'stupid' with 'upid': 80%&lt;br /&gt;Comparing 'stupid' with 'stuuupid': 86%&lt;br /&gt;Comparing 'stupid' with 'sstuuupiiid': 71%&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;?&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-821483336045471362?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/821483336045471362/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=821483336045471362' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/821483336045471362'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/821483336045471362'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2009/05/how-to-use-similartext-function-to.html' title='How to use the similar_text function  to compare similar words'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-3526012662496842762</id><published>2009-05-25T10:58:00.000-07:00</published><updated>2009-05-25T10:59:01.954-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='soundex function in php'/><category scheme='http://www.blogger.com/atom/ns#' term='Use the soundex() function to test if words sound similar'/><category scheme='http://www.blogger.com/atom/ns#' term='soundex function'/><title type='text'>Use the soundex() function to test if words sound similar</title><content type='html'>&lt;?php&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;** Function: soundex (PHP)&lt;br /&gt;** Desc: Shows how to use the soundex() function to test if words sounds similar.&lt;br /&gt;** Example: see below&lt;br /&gt;** Author: Jonas John&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;$word2find = 'stupid';&lt;br /&gt;&lt;br /&gt;$words = array(&lt;br /&gt;    'stupid',&lt;br /&gt;    'stu and pid',&lt;br /&gt;    'hello',&lt;br /&gt;    'foobar',&lt;br /&gt;    'stpid',&lt;br /&gt;    'supid',&lt;br /&gt;    'stuuupid',&lt;br /&gt;    'sstuuupiiid',&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;while(list($id, $str) = each($words))&lt;br /&gt;{&lt;br /&gt;    $soundex_code = soundex($str);&lt;br /&gt;&lt;br /&gt;    if (soundex($word2find) == $soundex_code)&lt;br /&gt;    {&lt;br /&gt;        print '"' . $word2find . '" sounds like ' . $str;&lt;br /&gt;    }&lt;br /&gt;    else {&lt;br /&gt;        print '"' . $word2find . '" sounds not like ' . $str;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    print "\n";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;result:&lt;br /&gt;&lt;br /&gt;"stupid" sounds like stupid&lt;br /&gt;"stupid" sounds not like stu and pid&lt;br /&gt;"stupid" sounds not like hello&lt;br /&gt;"stupid" sounds not like foobar&lt;br /&gt;"stupid" sounds like stpid&lt;br /&gt;"stupid" sounds not like supid&lt;br /&gt;"stupid" sounds like stuuupid&lt;br /&gt;"stupid" sounds like sstuuupiiid&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;?&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-3526012662496842762?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/3526012662496842762/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=3526012662496842762' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/3526012662496842762'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/3526012662496842762'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2009/05/use-soundex-function-to-test-if-words.html' title='Use the soundex() function to test if words sound similar'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-3137251613822821479</id><published>2009-05-25T10:57:00.003-07:00</published><updated>2009-05-25T10:57:53.995-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='perg_replace technique'/><title type='text'>perg_replace technique</title><content type='html'>&lt;?php&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt; This is a useful technique for passing matched data into other&lt;br /&gt; functions to be evaluated and replaced in parsed strings.&lt;br /&gt;&lt;br /&gt; This example is simple. It rewrites the &lt;img&gt; tag emulating being&lt;br /&gt; passed thru a proxy.&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;$html = file_get_contents('http://www.yahoo.com/');&lt;br /&gt;print "$html&lt;br&gt;&lt;br&gt;";&lt;br /&gt;$attr= 'src';&lt;br /&gt;$webroot='proxy';&lt;br /&gt;$html=preg_replace('/(\s)?'.$attr.'="([^\s]*?)"/ei',&lt;br /&gt;                   "make_new_img_tag('$attr','$2','$1','$webroot');",&lt;br /&gt;                   $html);&lt;br /&gt;print "&lt;!-- $html --&gt;";&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;function make_new_img_tag($attr, $filename, $prefix, $webroot) {&lt;br /&gt;    $b64val = base64_encode($filename);&lt;br /&gt;    return $prefix$attr.'="'.$webroot.'/browse/'.$b64val.'"';&lt;br /&gt;}&lt;br /&gt;?&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-3137251613822821479?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/3137251613822821479/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=3137251613822821479' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/3137251613822821479'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/3137251613822821479'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2009/05/pergreplace-technique.html' title='perg_replace technique'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-4758580541171841343</id><published>2009-05-25T10:57:00.001-07:00</published><updated>2009-05-25T10:57:17.642-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Checks whether $string begins with $search'/><title type='text'>Checks whether $string begins with $search</title><content type='html'>&lt;?php&lt;br /&gt; // Checks whether $string begins with $search&lt;br /&gt; function string_begins_with($string, $search)&lt;br /&gt; {&lt;br /&gt;     return (strncmp($string, $search, strlen($search)) == 0);&lt;br /&gt; }&lt;br /&gt;?&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-4758580541171841343?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/4758580541171841343/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=4758580541171841343' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/4758580541171841343'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/4758580541171841343'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2009/05/checks-whether-string-begins-with.html' title='Checks whether $string begins with $search'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-4098212771002366161</id><published>2009-05-25T10:56:00.001-07:00</published><updated>2009-05-25T10:56:47.555-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Make String usable as a URI'/><title type='text'>Make String usable as a URI</title><content type='html'>&lt;?php&lt;br /&gt;&lt;br /&gt;function dirify($s) {&lt;br /&gt;     $s = convert_high_ascii($s);  ## convert high-ASCII chars to 7bit.&lt;br /&gt;     $s = strtolower($s);           ## lower-case.&lt;br /&gt;     $s = strip_tags($s);       ## remove HTML tags.&lt;br /&gt;     $s = preg_replace('!&amp;[^;\s]+;!','',$s);         ## remove HTML entities.&lt;br /&gt;     $s = preg_replace('![^\w\s.]!','',$s);           ## remove non-word/space/period chars.&lt;br /&gt;     $s = preg_replace('!\s+!','-',$s);               ## change space chars to dashes.&lt;br /&gt;     return $s;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function convert_high_ascii($s) {&lt;br /&gt;         $HighASCII = array(&lt;br /&gt;                 "!\xc0!" =&gt; 'A',    # A`&lt;br /&gt;                 "!\xe0!" =&gt; 'a',    # a`&lt;br /&gt;                 "!\xc1!" =&gt; 'A',    # A'&lt;br /&gt;                 "!\xe1!" =&gt; 'a',    # a'&lt;br /&gt;                 "!\xc2!" =&gt; 'A',    # A^&lt;br /&gt;                 "!\xe2!" =&gt; 'a',    # a^&lt;br /&gt;                 "!\xc4!" =&gt; 'Ae',   # A:&lt;br /&gt;                 "!\xe4!" =&gt; 'ae',   # a:&lt;br /&gt;                 "!\xc3!" =&gt; 'A',    # A~&lt;br /&gt;                 "!\xe3!" =&gt; 'a',    # a~&lt;br /&gt;                 "!\xc8!" =&gt; 'E',    # E`&lt;br /&gt;                 "!\xe8!" =&gt; 'e',    # e`&lt;br /&gt;                 "!\xc9!" =&gt; 'E',    # E'&lt;br /&gt;                 "!\xe9!" =&gt; 'e',    # e'&lt;br /&gt;                 "!\xca!" =&gt; 'E',    # E^&lt;br /&gt;                 "!\xea!" =&gt; 'e',    # e^&lt;br /&gt;                 "!\xcb!" =&gt; 'Ee',   # E:&lt;br /&gt;                 "!\xeb!" =&gt; 'ee',   # e:&lt;br /&gt;                 "!\xcc!" =&gt; 'I',    # I`&lt;br /&gt;                 "!\xec!" =&gt; 'i',    # i`&lt;br /&gt;                 "!\xcd!" =&gt; 'I',    # I'&lt;br /&gt;                 "!\xed!" =&gt; 'i',    # i'&lt;br /&gt;                 "!\xce!" =&gt; 'I',    # I^&lt;br /&gt;                 "!\xee!" =&gt; 'i',    # i^&lt;br /&gt;                 "!\xcf!" =&gt; 'Ie',   # I:&lt;br /&gt;                 "!\xef!" =&gt; 'ie',   # i:&lt;br /&gt;                 "!\xd2!" =&gt; 'O',    # O`&lt;br /&gt;                 "!\xf2!" =&gt; 'o',    # o`&lt;br /&gt;                 "!\xd3!" =&gt; 'O',    # O'&lt;br /&gt;                 "!\xf3!" =&gt; 'o',    # o'&lt;br /&gt;                 "!\xd4!" =&gt; 'O',    # O^&lt;br /&gt;                 "!\xf4!" =&gt; 'o',    # o^&lt;br /&gt;                 "!\xd6!" =&gt; 'Oe',   # O:&lt;br /&gt;                 "!\xf6!" =&gt; 'oe',   # o:&lt;br /&gt;                 "!\xd5!" =&gt; 'O',    # O~&lt;br /&gt;                 "!\xf5!" =&gt; 'o',    # o~&lt;br /&gt;                 "!\xd8!" =&gt; 'Oe',   # O/&lt;br /&gt;                 "!\xf8!" =&gt; 'oe',   # o/&lt;br /&gt;                 "!\xd9!" =&gt; 'U',    # U`&lt;br /&gt;                 "!\xf9!" =&gt; 'u',    # u`&lt;br /&gt;                 "!\xda!" =&gt; 'U',    # U'&lt;br /&gt;                 "!\xfa!" =&gt; 'u',    # u'&lt;br /&gt;                 "!\xdb!" =&gt; 'U',    # U^&lt;br /&gt;                 "!\xfb!" =&gt; 'u',    # u^&lt;br /&gt;                 "!\xdc!" =&gt; 'Ue',   # U:&lt;br /&gt;                 "!\xfc!" =&gt; 'ue',   # u:&lt;br /&gt;                 "!\xc7!" =&gt; 'C',    # ,C&lt;br /&gt;                 "!\xe7!" =&gt; 'c',    # ,c&lt;br /&gt;                 "!\xd1!" =&gt; 'N',    # N~&lt;br /&gt;                 "!\xf1!" =&gt; 'n',    # n~&lt;br /&gt;                 "!\xdf!" =&gt; 'ss'&lt;br /&gt;         );&lt;br /&gt;         $find = array_keys($HighASCII);&lt;br /&gt;         $replace = array_values($HighASCII);&lt;br /&gt;         $s = preg_replace($find,$replace,$s);&lt;br /&gt;     return $s;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-4098212771002366161?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/4098212771002366161/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=4098212771002366161' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/4098212771002366161'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/4098212771002366161'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2009/05/make-string-usable-as-uri.html' title='Make String usable as a URI'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-2430494676778868328</id><published>2009-05-25T10:55:00.000-07:00</published><updated>2009-05-25T10:56:01.916-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='convert string to hex in php'/><category scheme='http://www.blogger.com/atom/ns#' term='Convert String to Hex'/><title type='text'>Convert String to HEX</title><content type='html'>&lt;?php&lt;br /&gt;  function string2hex($string)&lt;br /&gt;  {&lt;br /&gt;    $hex = NULL;&lt;br /&gt;    for ($i=0; $i &lt; strlen($string); $i++)&lt;br /&gt;    {&lt;br /&gt;      $ord = ord(substr($string,$i,1));&lt;br /&gt;      if($ord &lt; 16) {&lt;br /&gt;    $hex.= '0'.dechex($ord);&lt;br /&gt;      } else {&lt;br /&gt;    $hex.= dechex($ord);&lt;br /&gt;      }&lt;br /&gt;      if ($i &amp;&amp; ($i % 32) == 31) {&lt;br /&gt;    $hex.= "\n";&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;    return $hex;&lt;br /&gt;  }&lt;br /&gt;?&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-2430494676778868328?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/2430494676778868328/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=2430494676778868328' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/2430494676778868328'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/2430494676778868328'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2009/05/convert-string-to-hex.html' title='Convert String to HEX'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-279573773186879855</id><published>2009-05-25T10:54:00.000-07:00</published><updated>2009-05-25T10:55:17.367-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Convert Hex to String in php'/><category scheme='http://www.blogger.com/atom/ns#' term='php Convert Hex to String'/><category scheme='http://www.blogger.com/atom/ns#' term='Convert Hex to String'/><title type='text'>Convert Hex to String</title><content type='html'>&lt;?php&lt;br /&gt;  function hex2string($hex)&lt;br /&gt;  {&lt;br /&gt;    $string = NULL;&lt;br /&gt;    $hex = str_replace(array("\n","\r"), "", $hex);&lt;br /&gt;    for ($i=0; $i &lt; $strlen($hex);$i++)&lt;br /&gt;    {&lt;br /&gt;      $string.= chr(hexdec(substr($hex, $i, 2)));&lt;br /&gt;    }&lt;br /&gt;    return $string;&lt;br /&gt;  }&lt;br /&gt;?&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-279573773186879855?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/279573773186879855/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=279573773186879855' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/279573773186879855'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/279573773186879855'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2009/05/convert-hex-to-string.html' title='Convert Hex to String'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-3436770030971826274</id><published>2009-05-25T10:51:00.000-07:00</published><updated>2009-05-25T10:52:57.625-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='php spell checker'/><category scheme='http://www.blogger.com/atom/ns#' term='spell checker in php'/><category scheme='http://www.blogger.com/atom/ns#' term='php text spell checker'/><title type='text'>PHP Text Spell Checker</title><content type='html'>&lt;?php&lt;br /&gt;// 2002-10-10 by Chris Snyder&lt;br /&gt;// this script uses aspell, but not the internal php spelling functions which are somewhat crippled by only being able to check words, not whole documents (as of ~php 4.2.2)&lt;br /&gt;// requires that aspell be installed and working at /usr/local/bin/aspell -- see http://aspell.sourceforge.net/&lt;br /&gt;&lt;br /&gt;// 2003-01-19 -- updated tempfile to use PHP's tempfile creation mech., also bumped year&lt;br /&gt;// 2003-01-24 -- fixed bug that caused improper handling of words with no suggested corrections (thanks, Dekeyzer Stephane!)&lt;br /&gt;// 2003-05-06 -- fixed a bug causing bad things to happen when multiple instances of incorrect words were found on any given line  (thanks, Dallas Brown!)&lt;br /&gt;//             -- also fixed script so that $opener and $closer work for custom labeling of errors (thanks again, Dallas Brown!)&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;spellcheck.php -- aspell-based spellchecker implemented in PHP&lt;br /&gt;Copyright (C) 2003 by Chris Snyder (csnyder@chxo.com)&lt;br /&gt;&lt;br /&gt;This program is free software; you can redistribute it and/or&lt;br /&gt;modify it under the terms of the GNU General Public License&lt;br /&gt;as published by the Free Software Foundation; either version 2&lt;br /&gt;of the License, or (at your option) any later version.&lt;br /&gt;&lt;br /&gt;This program is distributed in the hope that it will be useful,&lt;br /&gt;but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;GNU General Public License for more details.&lt;br /&gt;&lt;br /&gt;You should have received a copy of the GNU General Public License&lt;br /&gt;along with this program; if not, write to the Free Software&lt;br /&gt;Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;$text= $_POST['text'];&lt;br /&gt;$showsource= $_GET['showsource'];&lt;br /&gt;&lt;br /&gt;//&lt;br /&gt;// file paths and the aspell command have moved down below line 58&lt;br /&gt;//&lt;br /&gt;&lt;br /&gt;// show source code part I&lt;br /&gt;if ($showsource) $sourceinfo= "Script: $_SERVER[SCRIPT_FILENAME] ( &lt;a href="'#source'"&gt;source code&lt;/a&gt; )";&lt;br /&gt;else $sourceinfo= "&lt;a href="'$_SERVER[SCRIPT_NAME]?showsource="1#source'"&gt;show PHP source code&lt;/a&gt;";&lt;br /&gt;if (trim($text)!="") {&lt;br /&gt;    $showsource= 0;&lt;br /&gt;    $sourceinfo= "";&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;print "&lt;html&gt;&lt;br /&gt;&lt;head&gt;&lt;br /&gt;&lt;title&gt;$uripath&lt;/title&gt;&lt;br /&gt;&lt;style type="'text/css'"&gt;&lt;br /&gt;    body { font-family: Verdana, Geneva, sans-serif; font-size: 12px; line-height: 18px; background-color: #ffffdd;}&lt;br /&gt;    table { font-family: Verdana, Geneva, sans-serif; font-size: 12px; }&lt;br /&gt;    .heading { font-size: 12px; font-weight: bold; background-color: #666677; color: #dddddd; border: 1px; border-style: solid; }&lt;br /&gt;    .oddrow { background-color: #ffffff; }&lt;br /&gt;    .evenrow { background-color: #eeffee; }&lt;br /&gt;&lt;/style&gt;&lt;br /&gt;&lt;/head&gt;&lt;br /&gt;&lt;body&gt;&lt;br /&gt;&lt;h1&gt;Spell Check Some Text&lt;/h1&gt;&lt;br /&gt;&lt;p&gt;$sourceinfo&lt;/p&gt;";&lt;br /&gt;&lt;br /&gt;// if text+check is supplied, first open and create $temptext, then spell check&lt;br /&gt;if (trim($text)!="" &amp;amp;&amp;amp; ($_POST['submit']=="check" || $_POST['submit']=="re-check")) {&lt;br /&gt;&lt;br /&gt;    // HERE'S WHERE YOU MIGHT NEED TO CHANGE FILE PATHS, etc.&lt;br /&gt;    //&lt;br /&gt;    // set up some vars and create a tempfile&lt;br /&gt;    // tempnam() is a PHP function that creates a unique tempfile in the specified path,&lt;br /&gt;    //    with the specified prefix&lt;br /&gt;    $temptext= tempnam("/tmp", "spelltext");&lt;br /&gt;&lt;br /&gt;    // if you spellcheck alot of HTML, add the -H flag to aspell to put it in SGML mode&lt;br /&gt;    $aspellcommand= "cat $temptext | /usr/local/bin/aspell -a";&lt;br /&gt;&lt;br /&gt;    // these three determine how errors are flagged ($indicator is a description of what $opener and $closer do)&lt;br /&gt;    $indicator= "bold";&lt;br /&gt;    $opener= "&lt;b&gt;";&lt;br /&gt;    $closer= "&lt;/b&gt;";&lt;br /&gt;    //&lt;br /&gt;    // END OF CONFIGURATION&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    if ($fd=fopen($temptext,"w")) {&lt;br /&gt;        $textarray= explode("\n",$text);&lt;br /&gt;        fwrite($fd,"!\n");&lt;br /&gt;        foreach($textarray as $key=&gt;$value) {&lt;br /&gt;            // adding the carat to each line prevents the use of aspell commands within the text...&lt;br /&gt;            fwrite($fd,"^$value\n");&lt;br /&gt;            }&lt;br /&gt;        fclose($fd);&lt;br /&gt;&lt;br /&gt;        // next create tempdict and temprepl (skipping for now...)&lt;br /&gt;&lt;br /&gt;        // next run aspell&lt;br /&gt;        $return= shell_exec($aspellcommand);&lt;br /&gt;&lt;br /&gt;    // now unlink that tempfile&lt;br /&gt;    $ureturn= unlink($temptext);&lt;br /&gt;&lt;br /&gt;        //next parse $return and $text line by line, eh?&lt;br /&gt;        $returnarray= explode("\n",$return);&lt;br /&gt;        $returnlines= count($returnarray);&lt;br /&gt;        $textlines= count($textarray);&lt;br /&gt;&lt;br /&gt;        //print "text has $textlines lines and return has $returnlines lines.";&lt;br /&gt;        $lineindex= -1;&lt;br /&gt;        $poscorrect= 0;&lt;br /&gt;        $counter= 0;&lt;br /&gt;        foreach($returnarray as $key=&gt;$value) {&lt;br /&gt;            // if there is a correction here, processes it, else move the $textarray pointer to the next line&lt;br /&gt;            if (substr($value,0,1)=="&amp;amp;") {&lt;br /&gt;                //print "Line $lineindex correction:".$value."&lt;br /&gt;";&lt;br /&gt;                $correction= explode(" ",$value);&lt;br /&gt;                $word= $correction[1];&lt;br /&gt;                $absposition= substr($correction[3],0,-1)-1;&lt;br /&gt;                $position= $absposition+$poscorrect;&lt;br /&gt;                $niceposition= $lineindex.",".$absposition;&lt;br /&gt;                $suggstart= strpos($value,":")+2;&lt;br /&gt;                $suggestions= substr($value,$suggstart);&lt;br /&gt;                $suggestionarray= explode(", ",$suggestions);&lt;br /&gt;                //print "I found &lt;b&gt;$word&lt;/b&gt; at $position. Will suggest $suggestions.&lt;br /&gt;";&lt;br /&gt;&lt;br /&gt;                // highlight in text&lt;br /&gt;                $beforeword= substr($textarray[$lineindex],0,$position);&lt;br /&gt;                $afterword= substr($textarray[$lineindex],$position+strlen($word));&lt;br /&gt;                $textarray[$lineindex]= $beforeword."$opener$word$closer".$afterword;&lt;br /&gt;&lt;br /&gt;                // kludge for multiple words in one line ("&lt;b&gt;&lt;/b&gt;" adds 7 chars to subsequent positions, for instance)&lt;br /&gt;                $poscorrect= $poscorrect+strlen("$opener$closer");&lt;br /&gt;&lt;br /&gt;                // build the correction form&lt;br /&gt;                $counter= $counter+1;&lt;br /&gt;                $formbody.= "&lt;tr&gt;&lt;br /&gt;                                &lt;td align="'right'"&gt;$word&lt;/td&gt;&lt;br /&gt;                                &lt;td&gt;&lt;br /&gt;                                    &lt;input type="'hidden'" name="'position$counter'" value="'$niceposition'"&gt;&lt;br /&gt;                                    &lt;input type="'hidden'" name="'incorrect$counter'" value="\"&gt;&lt;br /&gt;                                    &lt;select name="'suggest$counter'" onchange="\" value="this.value;\"&gt;&lt;br /&gt;                                    &lt;option value="\"&gt;$word (as-is)&lt;/option&gt;&lt;br /&gt;                                    ";&lt;br /&gt;                foreach ($suggestionarray as $key=&gt;$value) {&lt;br /&gt;                    $formbody.= "&lt;option value="\"&gt;$value&lt;/option&gt;&lt;br /&gt;                                ";&lt;br /&gt;                    }&lt;br /&gt;                $inputlen= strlen($word)+5;&lt;br /&gt;                $formbody.= "&lt;option value="''"&gt;custom:&lt;/option&gt;&lt;br /&gt;                                    &lt;/select&gt;&lt;br /&gt;                                    &lt;input type="'text'" name="'correct$counter'" value="\" size="'$inputlen'"&gt;&lt;br /&gt;                                &lt;/td&gt;&lt;br /&gt;                              &lt;/tr&gt;";&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;            elseif (substr($value,0,1)=="#") {&lt;br /&gt;                //print "Line $lineindex unknown:".$value."&lt;br /&gt;";&lt;br /&gt;                $correction= explode(" ",$value);&lt;br /&gt;                $word= $correction[1];&lt;br /&gt;                $absposition= $correction[2] - 1;&lt;br /&gt;                $position= $absposition+$poscorrect;&lt;br /&gt;                $niceposition= $lineindex.",".$absposition;&lt;br /&gt;                $suggestions= "no suggestions";&lt;br /&gt;                $suggestionarray= explode(", ",$suggestions);&lt;br /&gt;                //print "I found &lt;b&gt;$word&lt;/b&gt; at $position. Will suggest $suggestions.&lt;br /&gt;";&lt;br /&gt;&lt;br /&gt;                // highlight in text&lt;br /&gt;                $beforeword= substr($textarray[$lineindex],0,$position);&lt;br /&gt;                $afterword= substr($textarray[$lineindex],$position+strlen($word));&lt;br /&gt;                $textarray[$lineindex]= $beforeword."$opener$word$closer".$afterword;&lt;br /&gt;&lt;br /&gt;                // kludge for multiple words in one line ("&lt;b&gt;&lt;/b&gt;" adds 7 chars to subsequent positions)&lt;br /&gt;                $poscorrect= $poscorrect+strlen("$opener$closer");&lt;br /&gt;&lt;br /&gt;                // build the correction form&lt;br /&gt;                $counter= $counter+1;&lt;br /&gt;                $formbody.= "&lt;tr&gt;&lt;br /&gt;                                &lt;td align="'right'"&gt;$word&lt;/td&gt;&lt;br /&gt;                                &lt;td&gt;&lt;br /&gt;                                    &lt;input type="'hidden'" name="'position$counter'" value="'$niceposition'"&gt;&lt;br /&gt;                                    &lt;input type="'hidden'" name="'incorrect$counter'" value="\"&gt;&lt;br /&gt;                                    &lt;select name="'suggest$counter'" onchange="\" value="this.value;\"&gt;&lt;br /&gt;                                    &lt;option value="\"&gt;$word (as-is)&lt;/option&gt;&lt;br /&gt;                                    ";&lt;br /&gt;                $inputlen= strlen($word)+3;&lt;br /&gt;                $formbody.= "&lt;option value="''"&gt;custom:&lt;/option&gt;&lt;br /&gt;                                    &lt;/select&gt;&lt;br /&gt;                                    &lt;input type="'text'" name="'correct$counter'" value="\" size="'$inputlen'"&gt;&lt;br /&gt;                                &lt;/td&gt;&lt;br /&gt;                              &lt;/tr&gt;";&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;            else {&lt;br /&gt;                //print "Done with line $lineindex, next line...&lt;br /&gt;&lt;br /&gt;";&lt;br /&gt;                $poscorrect=0;&lt;br /&gt;                $lineindex= $lineindex+1;&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    print "&lt;hr /&gt;Uncorrected Text (potential errors in $opener$indicator$closer):&lt;blockquote&gt;";&lt;br /&gt;    foreach ($textarray as $key=&gt;$value) {&lt;br /&gt;        print $value."&lt;br /&gt;";&lt;br /&gt;        }&lt;br /&gt;    print "&lt;/b&gt;&lt;!-- comment catcher --&gt;&lt;/blockquote&gt;";&lt;br /&gt;&lt;br /&gt;    $htmltext= htmlentities($text);&lt;br /&gt;    if ($formbody=="") $formbody= "&lt;tr&gt;&lt;td&gt; &lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;b&gt;No errors!&lt;/b&gt;&lt;br /&gt;Click 'correct' to continue with text unchanged.&lt;br /&gt; &lt;/td&gt;&lt;/tr&gt;";&lt;br /&gt;    print "&lt;hr /&gt;&lt;h3&gt;Correction form:&lt;/h3&gt;&lt;br /&gt;    &lt;form name="'corrector'" action="'spellcheck.php'" method="'post'"&gt;&lt;br /&gt;    &lt;input type="'hidden'" name="'text'" value="\"&gt;&lt;br /&gt;    &lt;table&gt;&lt;br /&gt;    $formbody&lt;br /&gt;    &lt;tr&gt;&lt;br /&gt;      &lt;td&gt; &lt;/td&gt;&lt;br /&gt;      &lt;td&gt;&lt;input type="'submit'" name="'submit'" value="'correct'"&gt;&lt;br /&gt;          &lt;input type="'reset'" name="'reset'" value="'reset"&gt;&lt;br /&gt;      &lt;/td&gt;&lt;br /&gt;    &lt;/tr&gt;&lt;br /&gt;    &lt;/table&gt;&lt;br /&gt;    &lt;/form&gt;";&lt;br /&gt;&lt;br /&gt;    //print "&lt;hr /&gt;Return:".nl2br($return);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;// or if text+correct is specified, make the indicated corrections&lt;br /&gt;elseif (trim($text)!="" &amp;amp;&amp;amp; $_POST['submit']=="correct") {&lt;br /&gt;    $textarray= explode("\n",$text);&lt;br /&gt;&lt;br /&gt;    $index= 1;&lt;br /&gt;    $lastlineindex= 0;&lt;br /&gt;    $poscorrect= 0;&lt;br /&gt;&lt;br /&gt;    // look through list of positions and make corrections&lt;br /&gt;    while (isset($_POST["position$index"])) {&lt;br /&gt;        $positionarray= explode(",",$_POST["position$index"]);&lt;br /&gt;        $lineindex= $positionarray[0];&lt;br /&gt;        $absposition= $positionarray[1];&lt;br /&gt;&lt;br /&gt;        if ($lastlineindex==$lineindex) {&lt;br /&gt;            $position= $absposition+$poscorrect;&lt;br /&gt;            }&lt;br /&gt;        else {&lt;br /&gt;            $poscorrect= 0;&lt;br /&gt;            $position= $absposition;&lt;br /&gt;            }&lt;br /&gt;        $lastlineindex= $lineindex;&lt;br /&gt;        $correct= $_POST["correct$index"];&lt;br /&gt;        $incorrect= $_POST["incorrect$index"];&lt;br /&gt;        //print "Found correction at $lineindex,$absposition. Replacing ";&lt;br /&gt;&lt;br /&gt;        $before= substr($textarray[$lineindex],0,$position);&lt;br /&gt;        $after= substr($textarray[$lineindex],$position+strlen($incorrect));&lt;br /&gt;        $textarray[$lineindex]= $before.$correct.$after;&lt;br /&gt;&lt;br /&gt;        $poscorrect= (strlen($correct)-strlen($incorrect))+$poscorrect;&lt;br /&gt;        //print "Position correction is now $poscorrect.&lt;br /&gt;";&lt;br /&gt;        $index= $index+1;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;    //print "Original text:&lt;br /&gt;";&lt;br /&gt;    //print nl2br($text);&lt;br /&gt;    //print "&lt;hr /&gt;";&lt;br /&gt;&lt;br /&gt;    foreach ($textarray as $key=&gt;$value) {&lt;br /&gt;        $newtext.=$value;&lt;br /&gt;        }&lt;br /&gt;    print "&lt;br /&gt;    &lt;form action="'spellcheck.php'" method="'post'"&gt;&lt;br /&gt;        &lt;h3&gt;Your Corrected Text:&lt;/h3&gt;&lt;br /&gt;&lt;br /&gt;        &lt;textarea name="'text'" cols="'60'" rows="'10'"&gt;$newtext&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;        &lt;input type="'submit'" name="'submit'" value="'re-check'"&gt; | &lt;a href="'spellcheck.php'"&gt;Clear/Restart&lt;/a&gt; | &lt;a href="'spellcheck.php?showsource="1#source'"&gt;Show Source&lt;/a&gt;&lt;br /&gt;    &lt;/form&gt;";&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;// otherwise, show the initial form&lt;br /&gt;else {&lt;br /&gt;    print "&lt;br /&gt;    &lt;form action="'spellcheck.php'" method="'post'"&gt;&lt;br /&gt;        Text to Check:&lt;br /&gt;&lt;br /&gt;        &lt;textarea name="'text'" cols="'60'" rows="'10'"&gt;$newtext&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;        &lt;input type="'submit'" name="'submit'" value="'check'"&gt;&lt;br /&gt;    &lt;/form&gt;";&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;// show source code part II&lt;br /&gt;if ($showsource) {&lt;br /&gt;    print "&lt;hr /&gt;&lt;a name="'source'"&gt; &lt;/a&gt;&lt;h1&gt;PHP Source:&lt;/h1&gt;";&lt;br /&gt;    $void= show_source($_SERVER['SCRIPT_FILENAME']);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;print "&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;spellcheck.php Copyright (C) 2003 by Chris Snyder&lt;br /&gt;&lt;br /&gt;This program comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are welcome&lt;br /&gt;to redistribute it under certain conditions; please refer to the&lt;br /&gt;&lt;a href="'http://www.gnu.org/licenses/gpl.html'"&gt;GNU General Public License&lt;/a&gt; for details.&lt;br /&gt;&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;";&lt;br /&gt;?&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-3436770030971826274?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/3436770030971826274/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=3436770030971826274' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/3436770030971826274'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/3436770030971826274'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2009/05/php-text-spell-checker.html' title='PHP Text Spell Checker'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-6850982670810014201</id><published>2008-11-17T05:14:00.000-08:00</published><updated>2008-11-17T05:21:09.500-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='add days'/><category scheme='http://www.blogger.com/atom/ns#' term='php add days'/><category scheme='http://www.blogger.com/atom/ns#' term='add days to current date'/><title type='text'>Add Days to a Date</title><content type='html'>DATE Function in PHP  - ADD DAYS&lt;br /&gt;By using this function you can easily Add days into date and as well as subtract days from date.&lt;br /&gt;&lt;br /&gt;&lt;?&lt;br /&gt;//Example&lt;br /&gt;$date = "2008-11-10";&lt;br /&gt;$fdate = adddays($date,5);&lt;br /&gt;echo fdate;  //result : 2008-11-15&lt;br /&gt;&lt;br /&gt;$date = "2008-11-10";&lt;br /&gt;$fdate = adddays($date,-5);&lt;br /&gt;echo fdate;  //result : 2008-11-05&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    function adddays($date,$days){&lt;br /&gt;        $rs = $this-&gt;execute("select DATE_FORMAT(DATE_ADD('$date',INTERVAL $days DAY),'%Y-%m-%d') as newdate");&lt;br /&gt;        if($row = $this-&gt;row($rs)){&lt;br /&gt;            return $row["newdate"];&lt;br /&gt;        }else{&lt;br /&gt;            return "0000-00-00";&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;?&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-6850982670810014201?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/6850982670810014201/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=6850982670810014201' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/6850982670810014201'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/6850982670810014201'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/11/add-days-to-date.html' title='Add Days to a Date'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-8007934774683197108</id><published>2008-11-17T04:49:00.000-08:00</published><updated>2008-11-17T04:52:44.358-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL date format'/><category scheme='http://www.blogger.com/atom/ns#' term='convert into sql date foramt'/><category scheme='http://www.blogger.com/atom/ns#' term='date format'/><category scheme='http://www.blogger.com/atom/ns#' term='Format date'/><title type='text'>Convert Date into SQL Date Format</title><content type='html'>In this function you can easily convert user input date format into SQL date format.&lt;br /&gt;this 00/00/0000 to 0000-00-00&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;?&lt;br /&gt;$date = "15/11/2008";&lt;br /&gt;$query = "INSERT INTO TB VALUES('".tosqldate($date)."')";&lt;br /&gt;// result: 2008-11-15&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;function tosqldate($strdata){&lt;br /&gt;        $strdata = trim($strdata);&lt;br /&gt;        if($strdata==""){&lt;br /&gt;            return "";&lt;br /&gt;        }&lt;br /&gt;        $arrdate = explode("/",$strdata);&lt;br /&gt;        if(count($arrdate) &lt; 3){&lt;br /&gt;            return "";&lt;br /&gt;        }else{&lt;br /&gt;            return $arrdate[2]."-".$arrdate[1]."-".$arrdate[0];&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;?&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-8007934774683197108?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/8007934774683197108/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=8007934774683197108' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/8007934774683197108'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/8007934774683197108'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/11/convert-date-into-sql-date-format.html' title='Convert Date into SQL Date Format'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-7521776032502943410</id><published>2008-11-17T04:45:00.000-08:00</published><updated>2008-11-17T04:49:25.606-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='php date format'/><category scheme='http://www.blogger.com/atom/ns#' term='date format'/><category scheme='http://www.blogger.com/atom/ns#' term='date format php'/><category scheme='http://www.blogger.com/atom/ns#' term='Format date'/><title type='text'>Chage Date Format</title><content type='html'>&lt;span style="font-family: verdana;"&gt;By use of this script or function you can easily change date format: this 2008-11-15 to 15/11/2008&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;&lt;?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;// calling function  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;$date = "2008-11-15";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;$fdate = formatdae($date);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;echo $fdate;  // Result: 15/11/2008&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt; function formatdate($mysql_stamp,$type=1)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt; {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  //$type = 1 date + time&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  //$type = 2 date&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  //$type = 3 time&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  // split mysql DATETIME stamp into date and time&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  if($mysql_stamp==""){&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   return "";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  @list($date, $time) = split ('[ ]', $mysql_stamp);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  @list($year, $month, $day) = split ('[-]', $date);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  if( isset($time) &amp;amp;&amp;amp; $time != "" )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   list($hour, $minute, $second) = split ('[:]', $time);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   if($hour&gt;=12)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    $ext = "PM";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    $hour = $hour - 12;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    $ext = "AM";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   $time =  " ".$hour.":".$minute." ".$ext;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   $hour="";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   $minute= "" ;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   $ext = "";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   $time = "";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  }&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  if($type == 1)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   $formatted_stamp = "$day/$month/$year".$time;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  elseif($type==2)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   $formatted_stamp = "$day/$month/$year";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  elseif($type==3)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   $formatted_stamp = $time;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  return $formatted_stamp;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt; }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;?&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-7521776032502943410?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/7521776032502943410/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=7521776032502943410' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/7521776032502943410'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/7521776032502943410'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/11/chage-date-format.html' title='Chage Date Format'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-3626805153509979397</id><published>2008-11-13T02:36:00.000-08:00</published><updated>2008-11-13T03:14:58.218-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='php interviews'/><category scheme='http://www.blogger.com/atom/ns#' term='PHP interview questions'/><title type='text'>PHP interview Question</title><content type='html'>&lt;div style="text-align: left; font-family: arial;"&gt;&lt;ol&gt;&lt;li&gt;How can we repair a MySQL table?&lt;/li&gt;&lt;li&gt;What are the advantages of stored procedures, triggers, indexes? &lt;/li&gt;&lt;li&gt;What is the maximum length of a table name, database name, and fieldname in MySQL?&lt;/li&gt;&lt;li&gt;How many values can the SET function of MySQL take?&lt;/li&gt;&lt;li&gt;What are the other commands to know the structure of table using MySQL commands except explain command?&lt;/li&gt;&lt;p&gt;&lt;span id="more-175"&gt;&lt;/span&gt;&lt;/p&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-3626805153509979397?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/3626805153509979397/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=3626805153509979397' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/3626805153509979397'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/3626805153509979397'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/11/php-interview-question.html' title='PHP interview Question'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-840892678577915234</id><published>2008-11-13T02:21:00.000-08:00</published><updated>2008-11-13T02:28:59.140-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='php interview'/><category scheme='http://www.blogger.com/atom/ns#' term='interview preperation'/><category scheme='http://www.blogger.com/atom/ns#' term='php preperation'/><title type='text'>PHP interview Preperation</title><content type='html'>&lt;span style="font-size:85%;"&gt;&lt;span style="font-family: verdana;"&gt;1. What does a special set of tags &lt;?= and ?&gt; do in PHP? - The output is displayed directly to the browser.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. What’s the difference between include and require? - It’s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what’s the problem? - PHP Interpreter treats numbers beginning with 0 as octal. Look at the similar PHP interview questions for more numeric problems.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. Would I use print "$a dollars" or "{$a} dollars" to print out the amount of dollars in this example? - In this example it wouldn’t matter, since the variable is all by itself, but if you were to print something like "{$a},000,000 mln dollars", then you definitely need to use the braces.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;5. How do you define a constant? - Via define() directive, like define ("MYCONSTANT", 100);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;6. How do you pass a variable by value? - Just like in C++, put an ampersand in front of it, like $a = &amp;amp;$b&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;7. Will comparison of string "10" and integer 11 work in PHP? - Yes, internally PHP will cast everything to the integer type, so numbers 10 and 11 will be compared.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: verdana;"&gt;8. When are you supposed to use endif to end the conditional statement? - When the original if was followed by : and then the code block without braces.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;9. Explain the ternary conditional operator in PHP? - Expression preceding the ? is evaluated, if it’s&lt;br /&gt;true, then the expression preceding the : is executed, otherwise, the expression following : is executed.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;10. How do I find out the number of parameters passed into function? - func_num_args() function returns the number of parameters passed in.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;11. If the variable $a is equal to 5 and variable $b is equal to character a, what’s the value of $$b? - 100, it’s a reference to existing variable.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;12. What’s the difference between accessing a class method via -&gt; and via ::? - :: is allowed to access methods that can perform static operations, i.e. those, which do not require object initialization.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;13. Are objects passed by value or by reference? - Everything is passed by value.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;14. How do you call a constructor for a parent class? - parent::constructor($value)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;15. What’s the special meaning of __sleep and __wakeup? - __sleep returns the array of all the&lt;br /&gt;variables than need to be saved, while __wakeup retrieves them.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;16. Why doesn’t the following code print the newline properly?    &lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;            $str = ‘Hello, there.\nHow are you?\nThanks for visiting TechInterviews’;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;            print $str;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    ?&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Because inside the single quotes the \n character is not interpreted as newline, just as a sequence of two characters - \ and n.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;17. Would you initialize your strings with single quotes or double quotes? - Since the data inside the single-quoted string is not parsed for variable substitution, it’s always a better idea speed-wise to initialize a string with single quotes, unless you specifically need variable substitution.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;18. How come the code &lt;?php print "Contents: $arr[1]"; ?&gt; works, but &lt;?php print "Contents: $arr[1][2]"; ?&gt; doesn’t for two-dimensional array of mine? - Any time you have an array with more than one dimension, complex parsing syntax is required. print "Contents: {$arr[1][2]}" would’ve worked.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;19. What is the difference between characters \023 and \x23? - The first one is octal 23, the second is hex 23.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;20. With a heredoc syntax, do I get variable substitution inside the heredoc contents? - Yes.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;21. I want to combine two variables together:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt; $var1 = 'Welcome to ';&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt; $var2 = 'TechInterviews.com';&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;What will work faster? Code sample 1:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;$var 3 = $var1.$var2;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Or code sample 2:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;$var3 = "$var1$var2";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Both examples would provide the same result - $var3 equal to "Welcome to TechInterviews.com". However, Code Sample 1 will work significantly faster. Try it out with large sets of data (or via concatenating small sets a million times or so), and you will see that concatenation works significantly faster than variable substitution.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: verdana;"&gt;22. For printing out strings, there are echo, print and printf. Explain the differences. - echo is the most primitive of them, and just outputs the contents following the construct to the screen. print is also a construct (so parentheses are optional when calling it), but it returns TRUE on successful output and FALSE if it was unable to print out the string. However, you can pass multiple parameters to echo, like:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt; &lt;?php echo 'Welcome ', 'to', ' ', 'TechInterviews!'; ?&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;and it will output the string "Welcome to TechInterviews!" print does not take multiple parameters. It is also generally argued that echo is faster, but usually the speed advantage is negligible, and might not be there for future versions of PHP. printf  is a function, not a construct, and allows such advantages as formatted output, but it’s the slowest way to print out data out of echo, print and printf.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;23. I am writing an application in PHP that outputs a printable version of driving directions. It contains some long sentences, and I am a neat freak, and would like to make sure that no line exceeds 50 characters. How do I accomplish that with PHP? - On large strings that need to be formatted according to some length specifications, use wordwrap() or chunk_split().&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;24. What’s the output of the ucwords function in this example?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    $formatted = ucwords("TECHINTERVIEWS IS COLLECTION OF INTERVIEW QUESTIONS");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    print $formatted;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;What will be printed is TECHINTERVIEWS IS COLLECTION OF INTERVIEW QUESTIONS.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;ucwords() makes every first letter of every word capital, but it does not lower-case anything else. To avoid this, and get a properly formatted string, it’s worth using strtolower() first.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;25. What’s the difference between htmlentities() and htmlspecialchars()? - htmlspecialchars only takes care of &lt;, &gt;, single quote ‘, double quote " and ampersand. htmlentities translates all occurrences of character sequences that have different meaning in HTML.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: verdana;"&gt;26. What’s the difference between md5(), crc32() and sha1() crypto on PHP? - The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: verdana;"&gt;27. So if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()? - Crypto usage in PHP is simple, but that doesn’t mean it’s free. First off, depending on the data that you’re encrypting, you might have reasons to store a 32-bit value in the database instead of the 160-bit value to save on space. Second, the more secure the crypto is, the longer is the computation time to deliver the hash value. A high volume site might be significantly slowed down, if frequent md5() generation is required.&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-840892678577915234?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/840892678577915234/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=840892678577915234' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/840892678577915234'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/840892678577915234'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/11/php-interview-preperation.html' title='PHP interview Preperation'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-4628066321669129441</id><published>2008-11-13T02:13:00.000-08:00</published><updated>2008-11-13T02:16:00.129-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='required() and include()'/><category scheme='http://www.blogger.com/atom/ns#' term='required and include'/><category scheme='http://www.blogger.com/atom/ns#' term='Difference Between require and include'/><title type='text'>The Difference Between require() and include()</title><content type='html'>&lt;p style="font-family: verdana;"&gt;The key difference between require() and include() is that if you require() a file that can't be loaded (eg if it isn't there) then it generates a fatal error which will halt the execution of the page completely, and no more output will be generated. On the other hand, if you include() a file that can't be loaded, then this will merely generate a warning and continue building the page.&lt;/p&gt; &lt;p style="font-family: verdana;"&gt;What one you should use depends on the situation; require() is best suited for loading files that are essential to the rest of the page - for example if you have a database driven website then using require() to include a file containing the database login and password is clearly preferred over using include(). If you used include() in this situation, then you may end up generating more warnings and errors than you had intended.&lt;/p&gt; &lt;p style="font-family: verdana;"&gt;include() should be used when it isn't essential for that file to be loaded to execute the page. This is best used in situations where the file isn't essential to the processing of the page (for example a footer file), so if the file isn't present then the user can still view the site. You should, of course, make sure that all files you include() and require() are going to be available.&lt;/p&gt; &lt;p style="font-family: verdana;"&gt;In PHP versions prior to 4.0.2. there was slightly different behaviour of require(). If you used a require() statement in an if block then the require() statement will always make sure that the file you're require()ing is readable, regardless of whether the condition was true for that if block to be processed. This is best illustrated with the following code example:&lt;/p&gt;&lt;p style="color: rgb(153, 51, 0); font-family: verdana;"&gt;&lt;?&lt;br /&gt;  $a = 1;&lt;br /&gt;  if($a == 2) {&lt;br /&gt;    require("header.php");&lt;br /&gt;  }&lt;br /&gt;?&gt;&lt;/p&gt;&lt;p style="color: rgb(0, 102, 0); font-family: verdana;"&gt;In this example, PHP versions before 4.0.2. will always make sure that header.php is available, but it will only actually execute the contents of it if $a is equal to 2.&lt;/p&gt;&lt;p style="color: rgb(0, 102, 0); font-family: verdana;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="color: rgb(0, 102, 0); font-family: verdana; font-weight: bold;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;More Explanation:&lt;/span&gt;&lt;/p&gt;&lt;p style="color: rgb(0, 102, 0); font-family: verdana;"&gt;The principle differences between include() &amp;amp; require() are :&lt;br /&gt;(1).When “Include()”ed file is not found,only warnings will be displayed&amp;amp; the script will continue to execute further.&lt;br /&gt;       But,when “require()”ed file is not found,fatal errors will be displayed &amp;amp; the script will halt execution.&lt;br /&gt; When we are dealing with non-confedintial data,&lt;br /&gt;inlude()is preffered.&lt;br /&gt;e.g. When we are dealing with a form which posts Sachin Tendulkar’s age &amp;amp; no. of centuries ,after posting the form,&lt;br /&gt;the variables age &amp;amp; no.centuries will be displayed on the URL of the opened active file.&lt;br /&gt;If “include()” ed file doesn’t exist ,only waning will be given &amp;amp; the script will follow its execution afterwatds. &lt;/p&gt;&lt;p style="font-family: verdana;"&gt;with including “require()” in our file ,we can safely process over confidential data ,such as user login form. Here both login ID &amp;amp; passwords are checked &amp;amp; script will continue only when “require()” function gets required file,otherwise,it will halt the script showing fatal error.&lt;/p&gt;&lt;p style="color: rgb(0, 102, 0); font-family: verdana;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-4628066321669129441?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/4628066321669129441/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=4628066321669129441' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/4628066321669129441'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/4628066321669129441'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/11/difference-between-require-and-include.html' title='The Difference Between require() and include()'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-4521527444775646392</id><published>2008-09-12T06:13:00.000-07:00</published><updated>2008-09-12T06:16:54.222-07:00</updated><title type='text'>PHP htmlentities Function</title><content type='html'>&lt;span style="font-family:arial;"&gt;Whenever you allow your users to submit text to your website, you need to be careful that you don't leave any security holes open for &lt;/span&gt;&lt;span style="font-family:arial;"&gt;malicious users to exploit. If you are ever going to allow user submitted text to be visible by the public you should consider using the &lt;/span&gt;&lt;span style="font-family:arial;"&gt;htmlentities function to prevent them from running html code and scripts that may be harmful to your visitors.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;HP - Converting HTML into Entities&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The htmlentities function takes a string and returns the same string with HTML converted into HTML entities. For example, the string &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-weight: bold;font-family:arial;" &gt;"&lt;script&gt;" would be converted to "&lt;script&gt;".&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;By converting the &lt;&gt; into entities, it prevents the browser from using it as an HTML element and it prevents the code from &lt;/span&gt;&lt;span style="font-family:arial;"&gt;running if you were to display some user's input on your website.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;This may seem a little complicated, but if you think of the way a browser works, in separate stages, it becomes a little easier. Let's &lt;/span&gt;&lt;span style="font-family:arial;"&gt;look at the way the function htmlentities changes the data at three different levels: in PHP, in raw HTML and in the web browser. The &lt;/span&gt;&lt;span style="font-family:arial;"&gt;sample string is a bad script that will redirect visitors to the malicious user's own website.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;PHP Code:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=" color: rgb(204, 0, 0);font-family:arial;"&gt;// An imaginary article submission from a bad user&lt;/span&gt;&lt;br /&gt;&lt;span style=" color: rgb(204, 0, 0);font-family:arial;"&gt;//  it will redirect anyone to example.com if the code is run in a browser&lt;/span&gt;&lt;br /&gt;&lt;span style=" color: rgb(204, 0, 0);font-family:arial;"&gt;$userInput = "I am going to hax0r your site, hahaha!&lt;/span&gt;&lt;br /&gt;&lt;span style=" color: rgb(204, 0, 0);font-family:arial;"&gt;    &lt;script type="'text/javascript'"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=" color: rgb(204, 0, 0);font-family:arial;"&gt;    window.location = 'http://www.example.com/'&lt;/span&gt;&lt;br /&gt;&lt;span style=" color: rgb(204, 0, 0);font-family:arial;"&gt;    &lt;/script&gt;'";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;//Lets make it safer before we use it&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;$userInputEntities = htmlentities($userInput);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;//Now we can display it&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;echo $userInputEntities;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The HTML output of the above script would be as follows:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;Safe Raw HTML Code:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-weight: bold;font-family:arial;" &gt;I am going to hax0r your site, hahaha!&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-weight: bold;font-family:arial;" &gt;    &amp;lt; script type='text/javascript' &amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-weight: bold;font-family:arial;" &gt;    window.location = 'http://www.example.com/'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-weight: bold;font-family:arial;" &gt;    &amp;lt; /script &amp;gt;'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;If we had not used htmlentities to convert any HTML code into safe entities, this is what the raw HTML code would be and it would &lt;/span&gt;&lt;span style="font-family:arial;"&gt;have redirect a visitor to example.com.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Dangerous Raw HTML Code:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);font-family:arial;" &gt;I am going to hax0r your site, hahaha!&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);font-family:arial;" &gt;    &lt;script type="'text/javascript'"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=" color: rgb(0, 102, 0);font-family:arial;"&gt;    window.location = 'http://www.example.com/'&lt;/span&gt;&lt;br /&gt;&lt;span style=" color: rgb(0, 102, 0);font-family:arial;"&gt;    &lt;/script&gt;'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Those two HTML code examples are what you would see if you were to view source on the web page. However, if you were just &lt;/span&gt;&lt;span style="font-family:arial;"&gt;viewing the output normally in your browser you would see the following.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;Safe Display:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);font-family:arial;" &gt;I am going to hax0r your site, hahaha! &lt;script type="'text/javascript'"&gt; window.location = 'http://www.example.com/' &lt;/script&gt;'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Dangerous Display:&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;You'd see whatever spammer site that the malicious user had sent you to. Probably some herbal supplement site or weight loss pills &lt;/span&gt;&lt;span style="font-family:arial;"&gt;would be displayed.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;When Would You Use htmlentities?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Anytime you allow users to submit content to your website, that other visitors can see, you should consider removing the ability to let &lt;/span&gt;&lt;span style="font-family:arial;"&gt;them use HTML. Although this will remove a lot of cool things that your users can do, like making heavily customized content, it will &lt;/span&gt;&lt;span style="font-family:arial;"&gt;prevent your site from a lot of common attacks. With some custom coding you can just remove specific tags from running, but that is &lt;/span&gt;&lt;span style="font-family:arial;"&gt;beyond the scope of this lesson.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Just remember, that when allowing users to submit content to your site you are also giving them access to your website. Be sure you &lt;/span&gt;&lt;span style="font-family:arial;"&gt;take the proper precautions.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-4521527444775646392?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/4521527444775646392/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=4521527444775646392' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/4521527444775646392'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/4521527444775646392'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/09/php-htmlentities-function.html' title='PHP htmlentities Function'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-5580947999138177974</id><published>2008-09-12T06:03:00.000-07:00</published><updated>2008-09-12T06:12:41.844-07:00</updated><title type='text'>PHP - Filing</title><content type='html'>&lt;span style="font-family: arial;"&gt;Manipulating files is a basic necessity for serious programmers and PHP gives you a great deal of tools for creating, uploading, and &lt;/span&gt;&lt;span style="font-family: arial;"&gt;editing files. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This section of the PHP tutorial is completely dedicated to how PHP can interact with files. After completing this section you should &lt;/span&gt;&lt;span style="font-family: arial;"&gt;have a solid understanding of all types of file manipulation in PHP!&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;PHP - Files: Be Careful&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;When you are manipulating files you must be very careful because you can do a lot of damage if you do something wrong. Common &lt;/span&gt;&lt;span style="font-family: arial;"&gt;errors include editing the wrong file, filling a hard-drive with garbage data, and accidentally deleting a file's contents.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;It is our hope that you will be able to avoid these and other slipups after reading this tutorial. However, we know that there are so &lt;/span&gt;&lt;span style="font-family: arial;"&gt;many places where code can take a wrong turn, so we urge you to take extra care when dealing with files in PHP.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;PHP - Files: Overview&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The presentation of the file lessons will begin with how to create, open, and close a file. After establishing those basics, we will then &lt;/span&gt;&lt;span style="font-family: arial;"&gt;cover other important file tasks, such as: read, write, append, truncate, and uploading files with PHP.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;PHP - File Create##########&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Before you can do anything with a file it has to exist! In this lesson you will learn how to create a file using PHP.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;PHP - Creating Confusion&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;In PHP, a file is created using a command that is also used to open files. It may seem a little confusing, but we'll try to clarify this &lt;/span&gt;&lt;span style="font-family: arial;"&gt;conundrum.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;In PHP the fopen function is used to open files. However, it can also create a file if it does not find the file specified in the function &lt;/span&gt;&lt;span style="font-family: arial;"&gt;call. So if you use fopen on a file that does not exist, it will create it, given that you open the file for writing or appending (more on this &lt;/span&gt;&lt;span style="font-family: arial;"&gt;later).&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;PHP - How to Create a File&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The fopen function needs two important pieces of information to operate correctly. First, we must supply it with the name of the file &lt;/span&gt;&lt;span style="font-family: arial;"&gt;that we want it to open. Secondly, we must tell the function what we plan on doing with that file (i.e. read from the file, write &lt;/span&gt;&lt;span style="font-family: arial;"&gt;information, etc).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Since we want to create a file, we must supply a file name and tell PHP that we want to write to the file. Note: We have to tell PHP we &lt;/span&gt;&lt;span style="font-family: arial;"&gt;are writing to the file, otherwise it will not create a new file.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;PHP Code:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;$ourFileName = "testFile.txt";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;fclose($ourFileHandle);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The file "testFile.txt" should be created in the same directory where this PHP code resides. PHP will see that "testFile.txt" does not &lt;/span&gt;&lt;span style="font-family: arial;"&gt;exist and will create it after running this code. There's a lot of information in those three lines of code, let's make sure you understand &lt;/span&gt;&lt;span style="font-family: arial;"&gt;it.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;   1. $ourFileName = "testFile.txt";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    Here we create the name of our file, "testFile.txt" and store it into a PHP String variable $ourFileName.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;   2. $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   This bit of code actually has two parts. First we use the function fopen and give it two arguments: our file name and we inform &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;PHP that we want to write by passing the character "w".&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Second, the fopen function returns what is called a file handle, which will allow us to manipulate the file. We save the file handle &lt;/span&gt;&lt;span style="font-family: arial;"&gt;into the $ourFileHandle variable. We will talk more about file handles later on.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;   3. fclose($ourFileHandle);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   We close the file that was opened. fclose takes the file handle that is to be closed. We will talk more about this more in the file &lt;/span&gt;&lt;span style="font-family: arial;"&gt;closing lesson.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;PHP - Permissions&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If you are trying to get this program to run and you are having errors, you might want to check that you have granted your PHP file &lt;/span&gt;&lt;span style="font-family: arial;"&gt;access to write information to the hard drive. Setting permissions is most often done with the use of an FTP program to execute a &lt;/span&gt;&lt;span style="font-family: arial;"&gt;command called &lt;span style="font-weight: bold;"&gt;CHMOD&lt;/span&gt;. Use CHMOD to allow the PHP file to write to disk, thus allowing it to create a file.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;In the near future Tizag.com will have a more in-depth tutorial on how to use &lt;span style="font-weight: bold;"&gt;CHMOD&lt;/span&gt; to set file permissions. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;PHP - File Open###########&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;In the previous lesson we used the function fopen to create a new file. In this lesson we will be going into the details of this important &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;function and see what it has to offer.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;PHP - Different Ways to Open a File&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;For many different technical reasons, PHP requires you to specify your intentions when you open a file. Below are the three basic &lt;/span&gt;&lt;span style="font-family: arial;"&gt;ways to open a file and the corresponding character that PHP uses.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(51, 51, 255); font-weight: bold;"&gt;    * Read: 'r'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Open a file for read only use. The file pointer begins at the front of the file.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold; color: rgb(51, 51, 255);"&gt;    * Write: 'w'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Open a file for write only use. In addition, the data in the file is erased and you will begin writing data at the beginning of the file. This &lt;/span&gt;&lt;span style="font-family: arial;"&gt;is also called truncating a file, which we will talk about more in a later lesson. The file pointer begins at the start of the file.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   &lt;span style="font-weight: bold; color: rgb(51, 51, 255);"&gt; * Append: 'a'&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Open a file for write only use. However, the data in the file is preserved and you begin will writing data at the end of the file. The file &lt;/span&gt;&lt;span style="font-family: arial;"&gt;pointer begins at the end of the file.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;A file pointer is PHP's way of remembering its location in a file. When you open a file for reading, the file pointer begins at the start of &lt;/span&gt;&lt;span style="font-family: arial;"&gt;the file. This makes sense because you will usually be reading data from the front of the file.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;However, when you open a file for appending, the file pointer is at the end of the file, as you most likely will be appending data at the &lt;/span&gt;&lt;span style="font-family: arial;"&gt;end of the file. When you use reading or writing functions they begin at the location specified by the file pointer.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;PHP - Explanation of Different Types of fopen&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;These three basic ways to open a file have distinct purposes. If you want to get information out of a file, like search an e-book for the &lt;/span&gt;&lt;span style="font-family: arial;"&gt;occurrences of "cheese", then you would open the file for read only.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If you wanted to write a new file, or overwrite an existing file, then you would want to open the file with the "w" option. This would wipe &lt;/span&gt;&lt;span style="font-family: arial;"&gt;clean all existing data within the file.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If you wanted to add the latest order to your "orders.txt" file, then you would want to open it to append the data on to the end. This &lt;/span&gt;&lt;span style="font-family: arial;"&gt;would be the "a" option.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;PHP - File Open: Advanced&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;There are additional ways to open a file. Above we stated the standard ways to open a file. However, you can open a file in such a &lt;/span&gt;&lt;span style="font-family: arial;"&gt;way that reading and writing is allowable! This combination is done by placing a plus sign "+" after the file mode character.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold; color: rgb(51, 51, 255);"&gt;    * Read/Write: 'r+'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Opens a file so that it can be read from and written to. The file pointer is at the beginning of the file.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold; color: rgb(51, 51, 255);"&gt;    * Write/Read: 'w+'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This is exactly the same as r+, except that it deletes all information in the file when the file is opened.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold; color: rgb(51, 51, 255);"&gt;    * Append: 'a+'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This is exactly the same as r+, except that the file pointer is at the end of the file.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;PHP - File Open: Cookie Cutter&lt;/span&gt; &lt;span style="font-family: arial;"&gt;Below is the correct form for opening a file with PHP. Replace the (X) with one of the options above (i.e. r, w, a, etc).&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Pseudo PHP Code:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;$ourFileName = "testFile.txt";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;$fh = fopen($ourFileName, 'X') or die("Can't open file");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;fclose($fh);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;PHP - File Open: Summary&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;You can open a file in many different ways. You can delete everything and begin writing on a clean slate, you can add to existing data, &lt;/span&gt;&lt;span style="font-family: arial;"&gt;and you can simply read information from &lt;/span&gt;&lt;span style="font-family: arial;"&gt;a file. In later lessons we will go into greater detail on how each of these different ways to open a file is used in the real world and give &lt;/span&gt;&lt;span style="font-family: arial;"&gt;some helpful examples. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;PHP - File Close####################&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The next logical step after you have opened a file and finished your business with it is to close that file down. You don't want an open &lt;/span&gt;&lt;span style="font-family: arial;"&gt;file running around on your server taking up resources and causing mischief!&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;PHP - File Close Description&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;In PHP it is not system critical to close all your files after using them because the server will close all files after the PHP code finishes &lt;/span&gt;&lt;span style="font-family: arial;"&gt;execution. However the programmer is still free to make mistakes (i.e. editing a file that you accidentally forgot to close). You should &lt;/span&gt;&lt;span style="font-family: arial;"&gt;close all files after you have finished with them because it's a good programming practice and because we told you to!&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;PHP - File Close Function&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;In a previous tutorial, we had a call to the function fclose to close down a file after we were done with it. Here we will repeat that &lt;/span&gt;&lt;span style="font-family: arial;"&gt;example and discuss the importance of closing a file.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;PHP Code:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;$ourFileName = "testFile.txt";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;fclose($ourFileHandle);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The function fclose requires the file handle that we want to close down. In our example we set our variable "$fileHandle" equal to the &lt;/span&gt;&lt;span style="font-family: arial;"&gt;file handle returned by the fopen function.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;After a file has been closed down with fclose it is impossible to read, write or append to that file unless it is once more opened up with &lt;/span&gt;&lt;span style="font-family: arial;"&gt;the fopen function. Write, then this function might not work the way you expect it to.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;PHP - File Delete##########&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;You know how to create a file. You know how to open a file in an assortment of different ways. You even know how to read and write &lt;/span&gt;&lt;span style="font-family: arial;"&gt;data from a file! &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Now it's time to learn how to destroy (delete) files. In PHP you delete files by calling the unlink function.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;PHP - File Unlink&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;When you view the contents of a directory you can see all the files that exist in that directory because the operating system or &lt;/span&gt;&lt;span style="font-family: arial;"&gt;application that you are using displays a list of filenames. You can think of these filenames as links that join the files to the directory &lt;/span&gt;&lt;span style="font-family: arial;"&gt;you are currently viewing.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If you unlink a file, you are effectively causing the system to forget about it or delete it!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Before you can delete (unlink) a file, you must first be sure that it is not open in your program. Use the fclose function to close down &lt;/span&gt;&lt;span style="font-family: arial;"&gt;an open file.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;PHP - Unlink Function&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Remember from the PHP File Create lesson that we created a file named testFile.txt.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;PHP Code:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;$myFile = "testFile.txt";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;$fh = fopen($myFile, 'w') or die("can't open file");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;fclose($fh);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Now to delete testFile.txt we simply run a PHP script that is located in the same directory. Unlink just needs to know the name of the &lt;/span&gt;&lt;span style="font-family: arial;"&gt;file to start working its destructive magic.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;PHP Code:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;$myFile = "testFile.txt";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;unlink($myFile);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;The testFile.txt should now be removed.PHP - Unlink: Safety First!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;With great power comes a slough of potential things you can mess up! When you are performing the unlink function be sure that you &lt;/span&gt;&lt;span style="font-family: arial;"&gt;are deleting the right file! &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;PHP - File Append###########&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;So far we have learned how to open, close, read, and write to a file. However, the ways in which we have written to a file so far have &lt;/span&gt;&lt;span style="font-family: arial;"&gt;caused the data that was stored in the file to be deleted. If you want to append to a file, that is, add on to the existing data, then you &lt;/span&gt;&lt;span style="font-family: arial;"&gt;need to open the file in append mode.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;PHP - File Open: Append&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If we want to add on to a file we need to open it up in append mode. The code below does just that.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;PHP Code:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;$myFile = "testFile.txt";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;$fh = fopen($myFile, 'a');&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If we were to write to the file it would begin writing data at the end of the file.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;PHP - File Write: Appending Data&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Using the testFile.txt file we created in the File Write lesson , we are going to append on some more data.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;PHP Code:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;$myFile = "testFile.txt";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;$fh = fopen($myFile, 'a') or die("can't open file");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;$stringData = "New Stuff 1\n";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;fwrite($fh, $stringData);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;$stringData = "New Stuff 2\n";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;fwrite($fh, $stringData);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;fclose($fh);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;You should noticed that the way we write data to the file is exactly the same as in the Write lesson. The only thing that is different is &lt;/span&gt;&lt;span style="font-family: arial;"&gt;that the file pointer is placed at the end of the file in append mode, so all data is added to the end of the file.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The contents of the file testFile.txt would now look like this:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;Contents of the testFile.txt File:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(0, 102, 0);"&gt;Floppy Jalopy&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(0, 102, 0);"&gt;Pointy Pinto&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(0, 102, 0);"&gt;New Stuff 1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(0, 102, 0);"&gt;New Stuff 2&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;PHP - Append: Why Use It?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The above example may not seem very useful, but appending data onto a file is actually used everyday. Almost all web servers have &lt;/span&gt;&lt;span style="font-family: arial;"&gt;a log of some sort. These various logs keep track of all kinds of information, such as: errors, visitors, and even files that are installed &lt;/span&gt;&lt;span style="font-family: arial;"&gt;on the machine.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;A log is basically used to document events that occur over a period of time, rather than all at once. Logs: a perfect use for append! &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;PHP - File Truncate###########&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;As we have mentioned before, when you open a file for writing with the paramater 'w' it completely wipes all data from that file. This &lt;/span&gt;&lt;span style="font-family: arial;"&gt;action is also referred to as "truncating" a file. Truncate literally means to shorten.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;PHP - File Open: Truncate&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;To erase all the data from our testFile.txt file we need to open the file for normal writing. All existing data within testFile.txt will be lost.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;PHP Code:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;$myFile = "testFile.txt";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;$fh = fopen($myFile, 'w');&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(204, 0, 0);"&gt;fclose($fh);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;PHP - Truncate: Why Use It?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Truncating is most often used on files that contain data that will only be used for a short time, before needing to be replaced. These &lt;/span&gt;&lt;span style="font-family: arial;"&gt;type of files are most often referred to as temporary files.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;For example, you could create an online word processor that automatically saves every thirty seconds. Every time it saves it would &lt;/span&gt;&lt;span style="font-family: arial;"&gt;take all the data that existed within some HTML form text box and save it to the server. This file, say tempSave.txt, would be truncated &lt;/span&gt;&lt;span style="font-family: arial;"&gt;and overwritten with new, up-to-date data every thirty seconds.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This might not be the most efficient program, but it is a nice usage of truncate. &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-5580947999138177974?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/5580947999138177974/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=5580947999138177974' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/5580947999138177974'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/5580947999138177974'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/09/php-filing.html' title='PHP - Filing'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-1422122081144781028</id><published>2008-09-12T05:57:00.000-07:00</published><updated>2008-09-12T06:02:47.495-07:00</updated><title type='text'>PHP substr_replace Function</title><content type='html'>&lt;span style="font-family: arial;"&gt;The function substr_replace introduces some additional functionality to compliment str_replace. substr_replace is a more mathematically based replace function, which relies on starting points and lengths to replace parts of strings, as opposed to searching and replacing.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;substr_replace's Four Parameters&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;There are three required parameters for the substr_replace function (original string, replacement string, starting point) and one that's optional (length).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-family: arial;"&gt;1. original string - This is your original string that will be operated on.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-family: arial;"&gt;2. replacement string - This string will be used to replace everything in the string from the starting point to the ending point (specified by length).&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-family: arial;"&gt;3. starting point - This is the place in the original string that will be used to mark the replacement's beginning. A negative value specifies the number of characters from the end of the string.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-family: arial;"&gt;4. optional length - How many characters from the original string will be replaced. If no length is specified then the end of the string is used. If a value of 0 is used then no characters will be replaced and an insert is performed. A negative value specifies the number of characters from the end of the string.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;substr_replace On Your Mark&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This example of substr_replace shows what happens when you omit the length parameter at various starting points.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;PHP Code:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;//string that needs to be customized&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;$original = "ABC123 Hello Mr. Cow! DEF321";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;//starting point 5&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;$sp5 = substr_replace($original, "Five", 5);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;//starting point 12&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;$sp12 = substr_replace($original, "Twelve", 12);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;//starting point 0&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;$sp0 = substr_replace($original, "Zero", 0);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;//starting point -1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;$spneg1 = substr_replace($original, "Negative 1", -1);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;//Echo each string&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;echo "Original String: $original &lt;br /&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;echo "Starting Point 5: $sp5 &lt;br /&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;echo "Starting Point 12: $sp12 &lt;br /&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;echo "Starting Point 0: $sp0 &lt;br /&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;echo "Starting Point -1: $spneg1 ";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;Display:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Original String: ABC123 Hello Mr. Cow! DEF321&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Starting Point 5: ABC12Five&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Starting Point 12: ABC123 HelloTwelve&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Starting Point 0: Zero&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Starting Point -1: ABC123 Hello Mr. Cow! DEF32Negative 1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;As you can see, when you don't specify the fourth parameter, length, everything after the starting point is replaced by the second parameter replacement string.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255); font-family: arial;"&gt;Note: The first replacement occurred at position 5, which in $original was the character 3. This 3 and everything onward was replaced &lt;/span&gt;&lt;span style="font-family: arial;"&gt;with the replacement string. Remember that you start counting character to begin from zero. The $original string could be labeled as &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;so:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153); font-family: arial;"&gt;    * Letter A - Position 0&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153); font-family: arial;"&gt;    * Letter B - Position 1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153); font-family: arial;"&gt;    * Letter C - Position 2&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153); font-family: arial;"&gt;    * Letter 1 - Position 3&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153); font-family: arial;"&gt;    * Letter 2 - Position 4&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153); font-family: arial;"&gt;    * Letter 3 - Position 5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;substr_replace Specifying a Length&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If you want to get any sort of precision out of this function you're going to have to get into the nitty gritty of specifying the exact length of characters you want replaced in your original string.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Imagine that you want to get rid of those ugly pseudo references (ABC123, DEF321) at the beginning and end of the string. Since both of those strings are a length of 6 and we know one is at the very beginning of the string and the other is at the very end of the string &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;we should probably use a starting point of 0 for ABC123 and a value of -6 for DEF321. By having a replacement string of nothing "" we can do something similar to select and delete that we often do in a word processor.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;PHP Code:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;//string that needs to be customized&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;$original = "ABC123 Hello Mr. Cow! DEF321";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;//remove ABC123 and store in $cleanedstr&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;$cleanedstr = substr_replace($original, "", 0, 6);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;//remove DEF321 from $cleanedstr&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;$cleanedstr2 = substr_replace($cleanedstr, "", -6, 6);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;//Echo each string&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;echo "Original String: $original &lt;br /&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;echo "Clean #1: $cleanedstr &lt;br /&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;echo "Clean #2: $cleanedstr2";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Display:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Original String: ABC123 Hello Mr. Cow! DEF321&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Clean #1: Hello Mr. Cow! DEF321&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Clean #2: Hello Mr. Cow!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Make sure that you play around with this function some on your own so you can get a feel for how the starting point and length parameters effect this function.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;substr_replace Perform an Insert&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;By setting the length parameter to zero you can stop substr_replace from removing anything from the original string and just add to it. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If we wanted to add a second and third person to our $original string we would want to do this insert operation. Note: instead of counting the characters we've used a couple other PHP functions to figure out the starting positions for us.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;PHP Code:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;//string that needs to be customized&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;$original = "Hello Mr. Cow!";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;// Get the position of Mr. Cow&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;$cowpos = strpos($original, "Mr. Cow");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;// Find where Mr. Cow ends by adding the length of Mr. Cow&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;$cowpos_end = $cowpos + strlen("Mr. Cow");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;// Insert Mrs. Bear after Mr. Cow&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;$mrsbear = substr_replace($original, " and Mrs. Bear", $cowpos_end, 0);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;// Insert Sensei Shark before Mr. Cow&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;$senseishark = substr_replace($mrsbear, "Sensei Shark, ", $cowpos, 0);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;//Echo each string&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;echo "Original String: $original &lt;br /&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;echo "After Mrs. Bear: $mrsbear &lt;br /&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;echo "After Sensei Shark: $senseishark";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;Display:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Original String: Hello Mr. Cow!&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;After Mrs. Bear: Hello Mr. Cow and Mrs. Bear!&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;After Sensei Shark: Hello Sensei Shark, Mr. Cow and Mrs. Bear!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;We snuck a new function strlen into that example, but it isn't that complicated of a function, as it stands for "string length."&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0); font-family: arial;"&gt;    * $cowpos_end = $cowpos + strlen("Mr. Cow");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The strlen function takes a string and then counts up how many characters are in it then returns that number. So by calculating the length of "Mr. Cow" and adding that to the position, we find out where the end point is!&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-1422122081144781028?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/1422122081144781028/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=1422122081144781028' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/1422122081144781028'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/1422122081144781028'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/09/php-substrreplace-function.html' title='PHP substr_replace Function'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-5791449103931243906</id><published>2008-09-12T05:54:00.000-07:00</published><updated>2008-09-12T05:56:33.973-07:00</updated><title type='text'>PHP - String Explode</title><content type='html'>&lt;span style="font-family: arial;"&gt;The PHP function explode lets you take a string and blow it up into smaller pieces. For example, if you had a sentence you could ask &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;explode to use the sentence's spaces " " as dynamite and it would blow up the sentence into separate words, which would be stored &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;in an array. The sentence "Hello, I would like to lose weight." would look like this after explode got done with it:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 102, 51); font-family: arial;"&gt;   1.  Hello,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 102, 51); font-family: arial;"&gt;   2. I&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 102, 51); font-family: arial;"&gt;   3. would&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 102, 51); font-family: arial;"&gt;   4. like&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 102, 51); font-family: arial;"&gt;   5. to&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 102, 51); font-family: arial;"&gt;   6. lose&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 102, 51); font-family: arial;"&gt;   7. weight.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The dynamite (the space character) disappears, but the other stuff remains, but in pieces. With that abstract picture of the explode &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;function in mind, lets take a look at how it really works.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The explode Function&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The first argument that explode takes is the delimiter (our dynamite) which is used to blow up the second argument, the original string. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;explode returns an array of string pieces from the original and they are numbered in order, starting from 0. Lets take a phone number &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;in the form ###-###-#### and use a hyphen "-" as our dynamite to split the string into three separate chunks.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;PHP Code:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;$rawPhoneNumber = "800-555-5555"; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;$phoneChunks = explode("-", $rawPhoneNumber);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;echo "Raw Phone Number = $rawPhoneNumber &lt;br /&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;echo "First chunk = $phoneChunks[0]&lt;br /&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;echo "Second chunk = $phoneChunks[1]&lt;br /&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;echo "Third Chunk chunk = $phoneChunks[2]";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;Display:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Raw Phone Number = 800-555-5555&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;First chunk = 800&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Second chunk = 555&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Third Chunk chunk = 5555&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;explode Function - Setting a Limit&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If you want to control the amount of destruction that explode can wreak on your original string, consider using the third (optional) &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;argument which allows you to set the number of pieces explode can return. This means it will stop exploding once the number of &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;pieces equals the set limit. Below we've blown up a sentence with no limit and then with a limit of 4.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;PHP Code:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;$someWords = "Please don't blow me to pieces."; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;$wordChunks = explode(" ", $someWords);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;for($i = 0; $i &lt;&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;    echo "Piece $i = $wordChunks[$i] &lt;br /&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;$wordChunksLimited = explode(" ", $someWords, 4);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;for($i = 0; $i &lt;&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;    echo "Limited Piece $i = $wordChunksLimited[$i] &lt;br /&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;Display:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Piece 0 = Please&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Piece 1 = don't&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Piece 2 = blow&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Piece 3 = me&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Piece 4 = to&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Piece 5 = pieces.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Limited Piece 0 = Please&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Limited Piece 1 = don't&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Limited Piece 2 = blow&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Limited Piece 3 = me to pieces.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The limited explosion has 4 pieces (starting from 0, ending at 3). If you forgot how a for loop works, check out PHP For Loops.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-5791449103931243906?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/5791449103931243906/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=5791449103931243906' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/5791449103931243906'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/5791449103931243906'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/09/php-string-explode.html' title='PHP - String Explode'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-4632625339429777294</id><published>2008-09-12T05:49:00.000-07:00</published><updated>2008-09-12T05:53:11.244-07:00</updated><title type='text'>PHP - Array implode</title><content type='html'>&lt;div style="text-align: center; font-family: arial;"&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;PHP implode - Repairing the Damage&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The first argument of implode is the string of characters you want to use to join the array pieces together. The second argument is the array (pieces).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;PHP Code:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;$pieces = array("Hello", "World,", "I", "am", "Here!");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;$gluedTogetherSpaces = implode(" ", $pieces);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;$gluedTogetherDashes = implode("-", $pieces);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;for($i = 0; $i &lt;&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;    echo "Piece #$i = $pieces[$i] &lt;br /&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;echo "Glued with Spaces = $gluedTogetherSpaces &lt;br /&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;echo "Glued with Dashes = $gluedTogetherDashes";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;Display:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Piece #0 = Hello&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Piece #1 = World,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Piece #2 = I&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Piece #3 = am&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Piece #4 = Here!&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Glued with Spaces = Hello World, I am Here!&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-family: arial;"&gt;Glued with Dashes = Hello-World,-I-am-Here!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The implode function will convert the entire array into a string and there is no optional argument to limit this as there was in the explode function.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-4632625339429777294?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/4632625339429777294/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=4632625339429777294' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/4632625339429777294'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/4632625339429777294'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/09/php-array-implode.html' title='PHP - Array implode'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-5373111059445606122</id><published>2008-09-12T04:29:00.000-07:00</published><updated>2008-09-12T05:51:41.226-07:00</updated><title type='text'>PHP Pattern</title><content type='html'>&lt;span style="font-weight: bold;font-family:arial;" &gt;Singleton Pattern&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The singleton pattern applies to those situations in which there needs to be a single instance of a class. Implementing this pattern makes this single instance easily accessible by many other objects.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;Example&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;class Example&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;// Hold an instance of the class&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;private static $instance;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;// A private constructor; prevents direct creation of object&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;private function __construct()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;echo 'I am constructed';&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;// The singleton method&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;public static function singleton()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;if (!isset(self::$instance)) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;$c = __CLASS__;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;self::$instance = new $c;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;return self::$instance;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(204, 0, 0);font-family:arial;" &gt;// Example method&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;public function bark()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;echo 'Woof!';&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;// Prevent users to clone the instance&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;public function __clone()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;trigger_error('Clone is not allowed.', E_USER_ERROR);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt;?&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);font-family:arial;" &gt;Magic Methods&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;The function names _construct, _sleep, _wakeup, _tostring are all magical methods in PHP. There cannot be any functions with these names in the classes. These functions can be had only if we want the magical functionality associated with them.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);font-family:arial;" &gt;_sleep&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;The _sleep magic method is used to close any database connections that the object may have. It is also used to commit pending data and perform similar cleanup tasks. It is also used if there are very large objects which do not have to be saved completely.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);font-family:arial;" &gt;_wakeup&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;The _wakeup magic method is used to reconstruct any resources that the object may have. The basic function of _wakeup is to reestablish any database connections that may have been lost during serialization and perform other initialization tasks.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);font-family:arial;" &gt;Example of sleep and wakeup&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;class Conn {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;protected $link;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;private $server, $username, $password, $db;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;public function __construct($server, $username, $password, $db)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;$this-&gt;server = $server;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;$this-&gt;username = $username;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;$this-&gt;password = $password;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;$this-&gt;db = $db;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;$this-&gt;connect();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;private function connect()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;$this-&gt;link = mysql_connect($this-&gt;server, $this-&gt;username, $this-&gt;password);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;mysql_select_db($this-&gt;db, $this-&gt;link);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;public function __sleep()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;mysql_close($this-&gt;link);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;} &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);font-family:arial;" &gt;tostring&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;The _tostring magic method allows a class to decide that how it will react when it is converted to string.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);font-family:arial;" &gt;Example&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;// Declare a simple class&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;class Test&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;public $foo;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;public function __construct($foo) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;$this-&gt;foo = $foo;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;public function __toString() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;return $this-&gt;foo;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;$class = new Test('Hello');&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;echo $class;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;?&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);font-family:arial;" &gt;Cloning&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;An object copy is created by using the clone keyword. An object's __clone() method cannot be called directly. When an object is cloned, PHP will perform a shallow copy of all of the object's properties. Any properties that are references to other variables, will remain references. If a __clone() method is defined, then the newly created object's __clone() method will be called, to allow any necessary properties that need to be changed.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0); font-weight: bold;font-family:arial;" &gt;Example&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;class SubObject&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;static $instances = 0;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;public $instance;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;public function __construct() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;$this-&gt;instance = ++self::$instances;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;public function __clone() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;$this-&gt;instance = ++self::$instances;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;class MyCloneable&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;public $object1;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;public $object2;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;function __clone()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;// Force a copy of this-&gt;object, otherwise&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;// it will point to same object.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;$this-&gt;object1 = clone($this-&gt;object1);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;$obj = new MyCloneable();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;$obj-&gt;object1 = new SubObject();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;$obj-&gt;object2 = new SubObject();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;$obj2 = clone $obj;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;print("Original Object:\n");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;print_r($obj);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;print("Cloned Object:\n");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;print_r($obj2);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-5373111059445606122?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/5373111059445606122/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=5373111059445606122' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/5373111059445606122'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/5373111059445606122'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/09/php-pattern.html' title='PHP Pattern'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-1550912925915470581</id><published>2008-09-12T03:58:00.000-07:00</published><updated>2008-09-12T04:28:42.157-07:00</updated><title type='text'>PHP OOPS - Classes and Objects</title><content type='html'>&lt;span style="font-family:arial;"&gt;Classes and Objects are considered to be the most useful and dynamic aspects of a programming language. In PHP, classes are used extensively and are very useful. The concept of classes allows for better performance and more features.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;What is a Class?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The Class in PHP is basically the same as in other languages such as Java. The class definition begins with the keyword class, followed by a class name. The form name can be any name except a reserved word or keyword in PHP. The class name is followed by a pair of curly braces which contain the definition of class members and methods.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;Example of a Class&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;Class abc&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;//member functions and variables go here&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;?&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);font-family:arial;" &gt;What is an Object?&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;An Object is an enclosed bundle of variables and functions which is copied from a Class. Objects provide an easy interface and hide a lot of their inner workings. The object sends orders through special functions called methods and they can return information.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;While creating a Class, a set of characteristics is laid down. By creating Objects of that type, entities are created that share these characteristics but the Object might initialize them as different values.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);font-family:arial;" &gt;Example&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;Suppose there is a class named building. This class would have a characteristic named floor. All the objects of class building would share the characteristics of floor, but some would initialize it to “one”, some to “two”, others to “three” or “four”, and so on.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;The benefit of object oriented code is that it is re-useable. In this the classes can be used to create different objects and classes from one project can be used in other projects as well. Child classes can also be created which inherits the properties of the parent classes.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);font-family:arial;" &gt;Creating an Instance&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;To start with, a class having no member functions and variables is not useful. For a class to be completely useful, member functions and variables have to be added in that class.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;Let’s take an example of a class with a variable in it.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);font-family:arial;" &gt;Example&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;Class abc&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;$a = “Hello!”;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;?&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;The class abc is the basis from which many objects can be instantiated. The new keyword is used to create an object. Now any abc object that is created contains a property called $a with the value of “Hello”. This property can be accessed and even be changed with the help of objects.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);font-family:arial;" &gt;In this the -&gt; operator is used to access or change the properties of the object.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;In the following example $obj1 and $obj2 are the objects of the class abc. In this $obj2 has been assigned the string “Welcome to expertrating!” to its $a property.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);font-family:arial;" &gt;Example&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;Class abc&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;var $a = "Hello";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;$obj1 = new abc();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;$obj2 = new abc();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;$obj2-&gt;a = "Welcome to expertrating!";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;echo "$obj1-&gt;a&lt;br /&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;echo "$obj2-&gt;a&lt;br /&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;?&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;Extends&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Another feature of object oriented programming is used in PHP, which is inheritance. In PHP a class a class can inherit methods, functions and members of other class by using the extends keyword in the declaration. In PHP it is not possible to inherit from multiple classes, a class can inherit from only one base class.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The class from which inheritance is done is called the parent class or base class and the class which inherits is called the child class.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;The Keyword Final&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The final keyword prevents the child classes from overriding a method. This can be done by prefixing the method with the keyword final. If the complete class is being defined as final then that class cannot be extended.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;Example&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;final class test&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;//methods and functions&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The class defined above i.e. class test cannot be overloaded as it has been finalized by using the keyword final with it.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;Abstract&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;A new concept of abstract classes and methods has been introduced in PHP5. When a class is defined as abstract then it is not allowed to create the instance of that class. A class that contains at least one abstract method must also be abstract. The methods defined as abstract cannot define the implementation; they just declare the method’s signature.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;When a child class is inheriting from an abstract parent class, then all the methods marked abstract in parent class declaration must also be additionally defined by the child class. These methods must be defined with the same or weaker access. This means that if an abstract method is declared as protected in the parent class then it must be declared either as protected or public in the child class.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;Static Keyword&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;When class members or methods are declared as static then there is no need to instantiate that class. These members and methods are accessible without the instantiation of the class. If a member is declared as static then it cannot be accessed by an instantiated class object, but a method declared as static can be accessed by an instantiated class object.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The static declaration of a class must be after the visibility declaration (means that after the member or method has been declared as public, protected, or private).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The static method calls are resolved at compile time and static properties cannot be accessed through the object through the arrow operator (-&gt;).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;Interfaces&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Object interfaces allow the creation of a code which specifies that which method a class must implement, without having to define how these methods have to be handled.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Interfaces are defined in the same way as a class is defined. These interfaces are defined with the keyword “interface”. In the interface the contents of the methods do not have to be defined and all the methods declared in the interface must be declared as public.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Implementation of Interfaces&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;To implement an interface, the implements operator is used. The methods must be defined before implementation and all the methods in the interface must be implemented within a class.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;Exceptions&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Exception handling in PHP is similar to that of other programming languages. Within a PHP block of code we can throw, try and catch an exception. There must be at least one catch block in a try block. In this multiple catch blocks can be used to catch different class types. In exception handling the execution will continue after the last catch block has been encountered and exceptions can be thrown within catch blocks.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;In exception handling when an exception is thrown, the code following the statement will not be executed rather PHP will attempt to find the first matching catch block. If the exception is not caught then it will result in a fatal error with an uncaught exception message. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;This chapter will be focusing on some advanced class concepts, which will empower the reader to use classes in a better way and to create dynamic web pages.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;Constructor&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;In PHP 5 developers can declare constructor methods for classes. In this, those classes which have a constructor method call this method for each newly created object. So, it is suitable for any initialization that the object may need before it is used. In this the parent constructors are not called implicitly if the child class defines a constructor.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;Example&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;class ParentClass {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;function __construct() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;print "In ParentClass constructor\n";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;class ChildClass extends ParentClass {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;function __construct() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;parent::__construct();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;print "In ChildClass constructor\n";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;$obj = new ParentClass();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;$obj = new ChildClass();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;?&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);font-family:arial;" &gt;Destructors&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;The destructor concept is introduced in PHP 5. This destructor concept is similar to other object oriented languages. In this the destructor will be called as soon as all references to a particular object have been removed or when the object has been explicitly destroyed.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0); font-weight: bold;font-family:arial;" &gt;Example&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;class MyClass {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;function __construct() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;print "In constructor\n";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;$this-&gt;name = "MyClass";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;function __destruct() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;print "Destroying " . $this-&gt;name . "\n";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;$obj = new MyClass();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);font-family:arial;" &gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-1550912925915470581?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/1550912925915470581/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=1550912925915470581' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/1550912925915470581'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/1550912925915470581'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/09/php-oops-classes-and-objects.html' title='PHP OOPS - Classes and Objects'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-8469288141457263518</id><published>2008-09-12T03:51:00.000-07:00</published><updated>2008-09-12T03:57:30.992-07:00</updated><title type='text'>Advanced PHP Topics  - Superglobals</title><content type='html'>&lt;span style="font-family: arial;"&gt;In the previous chapters the concept of global variable was explained. A global variable is a variable declared at the top of the script outside the function. This variable is available to the complete script. Superglobal variables are arrays built into PHP. These superglobal variables are populated automatically with useful elements, and they are available in any scope. A superglobal array can be accessed within a function or a method without using the global keyword.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;PHP Superglobals&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    * $_COOKIE – It contains values provided to the script via HTTP cookies.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    * $_GET – It contains variables submitted to the script using HTTP get method.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    * $_POST – It contains variables submitted to the script using HTTP post method.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    * $_REQUEST – It is a combined array containing values from the $_GET, $_POST, and $_COOKIES superglobal arrays.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    * $_ENV – It contains keys and values set by the script’s shell.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    * $_FILES – It contains information about uploaded files.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    * $_SERVER – It contains variables made available by the server.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    * $GLOBALS – It contains all the global variables associated with the current script.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;&lt;br /&gt;Instanceof Operator&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The instanceof operator in PHP is used to determine whether a given object, the parents of that object, or its implemented interfaces are of a specified object class.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;&lt;br /&gt;Example&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;&lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;class X { }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;class Y { }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;$thing = new X;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;if ($thing instanceof X) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;echo 'X';&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;if ($thing instanceof Y) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;echo 'Y';&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;?&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;Declare&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The declare statement is used to set execution directives for a block of code. The syntax of the declare statement is similar to the syntax of other flow control statements.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Syntax&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;declare (directive)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;statement&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The directive section allows the behavior of the declare block to be set. In this only one directive is recognized, which is the ticks directive.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;[ Ticks - A tick is an event that occurs for every N low level statements, which are executed within the declare block. The value of N is specified using the statement ticks = N in the directive section.]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The statement part of the declare block will be executed according to the directives set in the directive block.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;&lt;br /&gt;Example&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;&lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;// how to use declare:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;// the first way:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;declare(ticks=1) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;// entire script here&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;// the second way:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;declare(ticks=1);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;// entire script here&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0); font-family: arial;"&gt;?&gt; &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-8469288141457263518?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/8469288141457263518/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=8469288141457263518' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/8469288141457263518'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/8469288141457263518'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/09/advanced-php-topics-superglobals.html' title='Advanced PHP Topics  - Superglobals'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-5839254169839213334</id><published>2008-09-07T01:12:00.000-07:00</published><updated>2008-09-07T01:18:44.168-07:00</updated><title type='text'>Resizing images with PHP</title><content type='html'>&lt;span style=";font-family:arial;font-size:100%;"  &gt;* File: SimpleImage.php&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 153, 51);"&gt;* Author: Simon Jarvis&lt;/span&gt;&lt;br /&gt;class SimpleImage {&lt;br /&gt;&lt;br /&gt;  var $image;&lt;br /&gt;  var $image_type;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;   function load($filename) {&lt;/span&gt;&lt;br /&gt;     $image_info = getimagesize($filename);&lt;br /&gt;     $this-&gt;image_type = $image_info[2];&lt;br /&gt;     if( $this-&gt;image_type == IMAGETYPE_JPEG ) {&lt;br /&gt;        $this-&gt;image = imagecreatefromjpeg($filename);&lt;br /&gt;     } elseif( $this-&gt;image_type == IMAGETYPE_GIF ) {&lt;br /&gt;        $this-&gt;image = imagecreatefromgif($filename);&lt;br /&gt;     } elseif( $this-&gt;image_type == IMAGETYPE_PNG ) {&lt;br /&gt;        $this-&gt;image = imagecreatefrompng($filename);&lt;br /&gt;     }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {&lt;/span&gt;&lt;br /&gt;     if( $image_type == IMAGETYPE_JPEG ) {&lt;br /&gt;        imagejpeg($this-&gt;image,$filename,$compression);&lt;br /&gt;     } elseif( $image_type == IMAGETYPE_GIF ) {&lt;br /&gt;        imagegif($this-&gt;image,$filename);       &lt;br /&gt;     } elseif( $image_type == IMAGETYPE_PNG ) {&lt;br /&gt;        imagepng($this-&gt;image,$filename);&lt;br /&gt;     } &lt;br /&gt;     if( $permissions != null) {&lt;br /&gt;        chmod($filename,$permissions);&lt;br /&gt;     }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;   function output($image_type=IMAGETYPE_JPEG) {&lt;/span&gt;&lt;br /&gt;     if( $image_type == IMAGETYPE_JPEG ) {&lt;br /&gt;        imagejpeg($this-&gt;image);&lt;br /&gt;     } elseif( $image_type == IMAGETYPE_GIF ) {&lt;br /&gt;        imagegif($this-&gt;image);       &lt;br /&gt;     } elseif( $image_type == IMAGETYPE_PNG ) {&lt;br /&gt;        imagepng($this-&gt;image);&lt;br /&gt;     } &lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;   function getWidth() {&lt;/span&gt;&lt;br /&gt;     return imagesx($this-&gt;image);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;   function getHeight() {&lt;/span&gt;&lt;br /&gt;     return imagesy($this-&gt;image);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;   function resizeToHeight($height) {&lt;/span&gt;&lt;br /&gt;     $ratio = $height / $this-&gt;getHeight();&lt;br /&gt;     $width = $this-&gt;getWidth() * $ratio;&lt;br /&gt;     $this-&gt;resize($width,$height);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;   function resizeToWidth($width) {&lt;/span&gt;&lt;br /&gt;     $ratio = $width / $this-&gt;getWidth();&lt;br /&gt;     $height = $this-&gt;getheight() * $ratio;&lt;br /&gt;     $this-&gt;resize($width,$height);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;   function scale($scale) {&lt;/span&gt;&lt;br /&gt;     $width = $this-&gt;getWidth() * $scale/100;&lt;br /&gt;     $height = $this-&gt;getheight() * $scale/100;&lt;br /&gt;     $this-&gt;resize($width,$height);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;   function resize($width,$height) {&lt;/span&gt;&lt;br /&gt;     $new_image = imagecreatetruecolor($width, $height);&lt;br /&gt;     imagecopyresampled($new_image, $this-&gt;image, 0, 0, 0, 0, $width, $height, $this-&gt;getWidth(), $this-&gt;getHeight());&lt;br /&gt;     $this-&gt;image = $new_image; &lt;br /&gt;  }    &lt;br /&gt;}&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3 style="font-family: arial;"&gt;-------------------Usage-------------------&lt;/h3&gt;Save the above file as SimpleImage.php and take a look at the following examples of how to use the script.  &lt;p style="font-family: arial;"&gt;The first example below will load a file named picture.jpg resize it to 250 pixels wide and 400 pixels high and resave it as picture2.jpg&lt;/p&gt;  &lt;div  style="margin: 5px 10px; overflow: auto; width: 95%;font-family:arial;"&gt;  &lt;div class="hl-main"&gt;&lt;pre&gt;&lt;span class="hl-inlinetags"&gt;&lt;span class="hl-code"&gt;&lt;?&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-reserved"&gt;include&lt;/span&gt;&lt;span class="hl-brackets"&gt;(&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-string"&gt;SimpleImage.php&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-brackets"&gt;)&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-var"&gt;$image&lt;/span&gt;&lt;span class="hl-code"&gt; = &lt;/span&gt;&lt;span class="hl-reserved"&gt;new&lt;/span&gt;&lt;span class="hl-code"&gt; &lt;/span&gt;&lt;span class="hl-identifier"&gt;SimpleImage&lt;/span&gt;&lt;span class="hl-brackets"&gt;()&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-var"&gt;$image&lt;/span&gt;&lt;span class="hl-code"&gt;-&gt;&lt;/span&gt;&lt;span class="hl-identifier"&gt;load&lt;/span&gt;&lt;span class="hl-brackets"&gt;(&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-string"&gt;picture.jpg&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-brackets"&gt;)&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-var"&gt;$image&lt;/span&gt;&lt;span class="hl-code"&gt;-&gt;&lt;/span&gt;&lt;span class="hl-identifier"&gt;resize&lt;/span&gt;&lt;span class="hl-brackets"&gt;(&lt;/span&gt;&lt;span class="hl-number"&gt;250&lt;/span&gt;&lt;span class="hl-code"&gt;,&lt;/span&gt;&lt;span class="hl-number"&gt;400&lt;/span&gt;&lt;span class="hl-brackets"&gt;)&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-var"&gt;$image&lt;/span&gt;&lt;span class="hl-code"&gt;-&gt;&lt;/span&gt;&lt;span class="hl-identifier"&gt;save&lt;/span&gt;&lt;span class="hl-brackets"&gt;(&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-string"&gt;picture2.jpg&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-brackets"&gt;)&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span class="hl-inlinetags"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt; &lt;/div&gt;   &lt;p style="font-family: arial;"&gt;If you want to resize to a specifed width but keep the dimensions ratio the same then the script can work out the required height for you, just use the resizeToWidth function.&lt;/p&gt;  &lt;div  style="margin: 5px 10px; overflow: auto; width: 95%;font-family:arial;"&gt;  &lt;div class="hl-main"&gt;&lt;pre&gt;&lt;span class="hl-inlinetags"&gt;&lt;span class="hl-code"&gt;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-reserved"&gt;include&lt;/span&gt;&lt;span class="hl-brackets"&gt;(&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-string"&gt;SimpleImage.php&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-brackets"&gt;)&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-var"&gt;$image&lt;/span&gt;&lt;span class="hl-code"&gt; = &lt;/span&gt;&lt;span class="hl-reserved"&gt;new&lt;/span&gt;&lt;span class="hl-code"&gt; &lt;/span&gt;&lt;span class="hl-identifier"&gt;SimpleImage&lt;/span&gt;&lt;span class="hl-brackets"&gt;()&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-var"&gt;$image&lt;/span&gt;&lt;span class="hl-code"&gt;-&gt;&lt;/span&gt;&lt;span class="hl-identifier"&gt;load&lt;/span&gt;&lt;span class="hl-brackets"&gt;(&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-string"&gt;picture.jpg&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-brackets"&gt;)&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-var"&gt;$image&lt;/span&gt;&lt;span class="hl-code"&gt;-&gt;&lt;/span&gt;&lt;span class="hl-identifier"&gt;resizeToWidth&lt;/span&gt;&lt;span class="hl-brackets"&gt;(&lt;/span&gt;&lt;span class="hl-number"&gt;250&lt;/span&gt;&lt;span class="hl-brackets"&gt;)&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-var"&gt;$image&lt;/span&gt;&lt;span class="hl-code"&gt;-&gt;&lt;/span&gt;&lt;span class="hl-identifier"&gt;save&lt;/span&gt;&lt;span class="hl-brackets"&gt;(&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-string"&gt;picture2.jpg&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-brackets"&gt;)&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span class="hl-inlinetags"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt; &lt;/div&gt;   &lt;p style="font-family: arial;"&gt;You may wish to scale an image to a specified percentage like the following which will resize the image to 50% of its original width and height&lt;/p&gt;  &lt;div  style="margin: 5px 10px; overflow: auto; width: 95%;font-family:arial;"&gt;  &lt;div class="hl-main"&gt;&lt;pre&gt;&lt;span class="hl-inlinetags"&gt;&lt;span class="hl-code"&gt;&lt;?&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-reserved"&gt;include&lt;/span&gt;&lt;span class="hl-brackets"&gt;(&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-string"&gt;SimpleImage.php&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-brackets"&gt;)&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-var"&gt;$image&lt;/span&gt;&lt;span class="hl-code"&gt; = &lt;/span&gt;&lt;span class="hl-reserved"&gt;new&lt;/span&gt;&lt;span class="hl-code"&gt; &lt;/span&gt;&lt;span class="hl-identifier"&gt;SimpleImage&lt;/span&gt;&lt;span class="hl-brackets"&gt;()&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-var"&gt;$image&lt;/span&gt;&lt;span class="hl-code"&gt;-&gt;&lt;/span&gt;&lt;span class="hl-identifier"&gt;load&lt;/span&gt;&lt;span class="hl-brackets"&gt;(&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-string"&gt;picture.jpg&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-brackets"&gt;)&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-var"&gt;$image&lt;/span&gt;&lt;span class="hl-code"&gt;-&gt;&lt;/span&gt;&lt;span class="hl-identifier"&gt;scale&lt;/span&gt;&lt;span class="hl-brackets"&gt;(&lt;/span&gt;&lt;span class="hl-number"&gt;50&lt;/span&gt;&lt;span class="hl-brackets"&gt;)&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-var"&gt;$image&lt;/span&gt;&lt;span class="hl-code"&gt;-&gt;&lt;/span&gt;&lt;span class="hl-identifier"&gt;save&lt;/span&gt;&lt;span class="hl-brackets"&gt;(&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-string"&gt;picture2.jpg&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-brackets"&gt;)&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span class="hl-inlinetags"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt; &lt;/div&gt;   &lt;p style="font-family: arial;"&gt;You can of course do more than one thing at once. The following example will create two new images with heights of 200 pixels and 500 pixels&lt;/p&gt;  &lt;div  style="margin: 5px 10px; overflow: auto; width: 95%;font-family:arial;"&gt;  &lt;div class="hl-main"&gt;&lt;pre&gt;&lt;span class="hl-inlinetags"&gt;&lt;span class="hl-code"&gt;&lt;?&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-reserved"&gt;include&lt;/span&gt;&lt;span class="hl-brackets"&gt;(&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-string"&gt;SimpleImage.php&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-brackets"&gt;)&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-var"&gt;$image&lt;/span&gt;&lt;span class="hl-code"&gt; = &lt;/span&gt;&lt;span class="hl-reserved"&gt;new&lt;/span&gt;&lt;span class="hl-code"&gt; &lt;/span&gt;&lt;span class="hl-identifier"&gt;SimpleImage&lt;/span&gt;&lt;span class="hl-brackets"&gt;()&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-var"&gt;$image&lt;/span&gt;&lt;span class="hl-code"&gt;-&gt;&lt;/span&gt;&lt;span class="hl-identifier"&gt;load&lt;/span&gt;&lt;span class="hl-brackets"&gt;(&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-string"&gt;picture.jpg&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-brackets"&gt;)&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-var"&gt;$image&lt;/span&gt;&lt;span class="hl-code"&gt;-&gt;&lt;/span&gt;&lt;span class="hl-identifier"&gt;resizeToHeight&lt;/span&gt;&lt;span class="hl-brackets"&gt;(&lt;/span&gt;&lt;span class="hl-number"&gt;500&lt;/span&gt;&lt;span class="hl-brackets"&gt;)&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-var"&gt;$image&lt;/span&gt;&lt;span class="hl-code"&gt;-&gt;&lt;/span&gt;&lt;span class="hl-identifier"&gt;save&lt;/span&gt;&lt;span class="hl-brackets"&gt;(&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-string"&gt;picture2.jpg&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-brackets"&gt;)&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-var"&gt;$image&lt;/span&gt;&lt;span class="hl-code"&gt;-&gt;&lt;/span&gt;&lt;span class="hl-identifier"&gt;resizeToHeight&lt;/span&gt;&lt;span class="hl-brackets"&gt;(&lt;/span&gt;&lt;span class="hl-number"&gt;200&lt;/span&gt;&lt;span class="hl-brackets"&gt;)&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-var"&gt;$image&lt;/span&gt;&lt;span class="hl-code"&gt;-&gt;&lt;/span&gt;&lt;span class="hl-identifier"&gt;save&lt;/span&gt;&lt;span class="hl-brackets"&gt;(&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-string"&gt;picture3.jpg&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-brackets"&gt;)&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span class="hl-inlinetags"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt; &lt;/div&gt;    &lt;p style="font-family: arial;"&gt;The output function lets you output the image straight to the browser without having to save the file. Its useful for on the fly thumbnail generation&lt;/p&gt;  &lt;div  style="margin: 5px 10px; overflow: auto; width: 95%;font-family:arial;"&gt;  &lt;div class="hl-main"&gt;&lt;pre&gt;&lt;span class="hl-inlinetags"&gt;&lt;span class="hl-code"&gt;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-identifier"&gt;header&lt;/span&gt;&lt;span class="hl-brackets"&gt;(&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-string"&gt;Content-Type: image/jpeg&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-brackets"&gt;)&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-reserved"&gt;include&lt;/span&gt;&lt;span class="hl-brackets"&gt;(&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-string"&gt;SimpleImage.php&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-brackets"&gt;)&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-var"&gt;$image&lt;/span&gt;&lt;span class="hl-code"&gt; = &lt;/span&gt;&lt;span class="hl-reserved"&gt;new&lt;/span&gt;&lt;span class="hl-code"&gt; &lt;/span&gt;&lt;span class="hl-identifier"&gt;SimpleImage&lt;/span&gt;&lt;span class="hl-brackets"&gt;()&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-var"&gt;$image&lt;/span&gt;&lt;span class="hl-code"&gt;-&gt;&lt;/span&gt;&lt;span class="hl-identifier"&gt;load&lt;/span&gt;&lt;span class="hl-brackets"&gt;(&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-string"&gt;picture.jpg&lt;/span&gt;&lt;span class="hl-quotes"&gt;'&lt;/span&gt;&lt;span class="hl-brackets"&gt;)&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-var"&gt;$image&lt;/span&gt;&lt;span class="hl-code"&gt;-&gt;&lt;/span&gt;&lt;span class="hl-identifier"&gt;resizeToWidth&lt;/span&gt;&lt;span class="hl-brackets"&gt;(&lt;/span&gt;&lt;span class="hl-number"&gt;150&lt;/span&gt;&lt;span class="hl-brackets"&gt;)&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt; &lt;/span&gt;&lt;span class="hl-var"&gt;$image&lt;/span&gt;&lt;span class="hl-code"&gt;-&gt;&lt;/span&gt;&lt;span class="hl-identifier"&gt;output&lt;/span&gt;&lt;span class="hl-brackets"&gt;()&lt;/span&gt;&lt;span class="hl-code"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span class="hl-inlinetags"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt; &lt;/div&gt;&lt;div  style="margin: 5px 10px; overflow: auto; width: 95%;font-family:arial;"&gt;&lt;div class="hl-main"&gt;&lt;pre&gt;&lt;span class="hl-inlinetags"&gt;&lt;span class="hl-code"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="hl-inlinetags"&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;More Information:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div style="text-align: left;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;This script will eventually be developed further to include functions&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;for easily sharpening, bluring, cropping, brightening and colouring images.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt; &lt;/div&gt;&lt;br /&gt;&lt;span style=";font-family:arial;font-size:100%;"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-5839254169839213334?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/5839254169839213334/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=5839254169839213334' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/5839254169839213334'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/5839254169839213334'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/09/resizing-images-with-php.html' title='Resizing images with PHP'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-8838165839276574622</id><published>2008-08-20T08:25:00.001-07:00</published><updated>2008-08-20T08:27:07.310-07:00</updated><title type='text'>PHP Source Code for Manually Registering Global Variables</title><content type='html'>&lt;h1&gt;Methodology and Implementation&lt;/h1&gt;&lt;br /&gt;&lt;p&gt;If you read up on the originial USENET thread, you know that there were a few suggestions made about going about this as well as posts pointing out why those solutions didn't quite fit. In order to get around some of the fallbacks and keep the original idea in tact, functions needed to be created.&lt;/p&gt;     &lt;p&gt;By making use of PHP's superglobal arrays ($GLOBALS, $_SESSION, $_GET, $_POST, $_COOKIE, $_REQUEST, $_SERVER, $_FILES, $_ENV) and referencing variables, the solution became rather simple to accommodate the OP's idea.&lt;/p&gt;     &lt;p&gt;You can read the thread to find out what brough on this interest if you are curious. What it comes down to is that the OP didn't want to trust register_globals, gpc_order and variables_order server settings to get it right. Therefore, the OP wanted a way to manually register the variables needed by pulling them from the appropriate place. This was to help the OP in creating more secure and stable PHP applications.&lt;/p&gt;     &lt;p&gt;How this works is really quite simple. Say you have a variable named "var1" in a session. This variable would normally be accessed by $_SESSION['var1'] if register_globals is not turned on. That syntax creates a few extra keystrokes as well as more extra strokes when using &lt;a href="http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc"&gt;heredoc syntax&lt;/a&gt; or quoted string output. However, if you were to be able to simply access that variable through $var1, that saves a lot of keystrokes when you start to use the variable over and over (as is likely the case with sessions and user input variables). For this to work correctly, however, if you were to set a value to the variable either through $var1 or $_SESSION['var1'], the compliment also needed to be changed. This is where variable references come in. (References are similar to pointers in the C programming language.)&lt;/p&gt;     &lt;p&gt;The implementation is bery easy to use. In order to "register" or global $var1 variable, we'd simply call the correct function from below.&lt;/p&gt;     &lt;pre class="example"&gt;global_session('var1');&lt;/pre&gt;     &lt;p&gt;In doing so, we now are able to access the same value in memory by the following 3 methods:&lt;/p&gt;     &lt;ul&gt;&lt;li&gt;$var1&lt;/li&gt;&lt;li&gt;$_SESSION['var1']&lt;/li&gt;&lt;li&gt;$GLOBALS['var1']&lt;/li&gt;&lt;/ul&gt;     &lt;p&gt;By setting a new value to any one of the above 3 variables will change the value for all of them.&lt;/p&gt;&lt;div&gt;     &lt;h1&gt;Difference From register_globals = On&lt;/h1&gt;     &lt;p&gt;One difference I have spotted in the way these functions act from having register_globals enabled is in the case of session variables. If you had altered $var1 in a script (with PHP's register_globals = "On"), you'd have to manually add the new value back into the session. In most cases, these functions would make a more convenient method; however, there may be instances where you do not want to have the $_SESSION variable automatically updated.&lt;/p&gt;     &lt;p&gt;Additional tests with other superglobal arrays reveal that the same behavior exists as above for all the superglobal arrays except $GLOBALS. Therefore, if you truly want to set global variable values globally, you would need to use the methods described on this page.&lt;/p&gt;    &lt;/div&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;global_get&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;){&lt;br /&gt;       if(!&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;array_key_exists&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_GET&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;))&lt;br /&gt;           &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_GET&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]=&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;''&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;       &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$GLOBALS&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]=&amp;amp;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_GET&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;global_post&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;){&lt;br /&gt;       if(!&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;array_key_exists&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;))&lt;br /&gt;           &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]=&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;''&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;       &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$GLOBALS&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]=&amp;amp;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;global_session&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;){&lt;br /&gt;       if(!&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;array_key_exists&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_SESSION&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;))&lt;br /&gt;           &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_SESSION&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]=&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;''&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;       &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$GLOBALS&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]=&amp;amp;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_SESSION&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;global_cookie&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;){&lt;br /&gt;       if(!&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;array_key_exists&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_COOKIE&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;))&lt;br /&gt;           &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_COOKIE&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]=&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;''&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;       &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$GLOBALS&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]=&amp;amp;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_COOKIE&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;global_server&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;){&lt;br /&gt;       if(!&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;array_key_exists&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_SERVER&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;))&lt;br /&gt;           &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_SERVER&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]=&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;''&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;       &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$GLOBALS&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]=&amp;amp;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_SERVER&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;global_files&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;){&lt;br /&gt;       if(!&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;array_key_exists&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_FILES&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;))&lt;br /&gt;           &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_FILES&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]=&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;''&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;       &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$GLOBALS&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]=&amp;amp;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_FILES&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;global_env&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;){&lt;br /&gt;       if(!&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;array_key_exists&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_ENV&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;))&lt;br /&gt;           &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_ENV&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]=&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;''&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;       &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$GLOBALS&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]=&amp;amp;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_ENV&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;global_request&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;){&lt;br /&gt;       if(!&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;array_key_exists&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_REQUEST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;))&lt;br /&gt;           &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_REQUEST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]=&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;''&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;       &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$GLOBALS&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]=&amp;amp;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_REQUEST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;   }&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-8838165839276574622?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/8838165839276574622/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=8838165839276574622' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/8838165839276574622'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/8838165839276574622'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/08/php-source-code-for-manually.html' title='PHP Source Code for Manually Registering Global Variables'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-6948263977165259592</id><published>2008-08-20T08:17:00.001-07:00</published><updated>2008-08-20T08:23:54.941-07:00</updated><title type='text'>Creating a chat script with PHP and Ajax</title><content type='html'>Introduction&lt;br /&gt;&lt;p&gt;In this  multi-part tutorial series I will show you how to create your own chat  script with PHP and Ajax. You've probably heard of Ajax before, and  what it exactly is, but in case you haven't, read the following two  tutorials to learn more about Ajax: &lt;a href="http://www-128.ibm.com/developerworks/web/library/wa-ajaxintro1.html?ca=dgr-lnxw01MasterAJAX"&gt;"Mastering Ajax, Part 1: Introduction to Ajax"&lt;/a&gt; and &lt;a href="http://devzone.skillfusion.com/ajaxArticle1.php"&gt;"Getting started with Ajax"&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Another JavaScript library we'll be using is the &lt;a href="http://prototype.conio.net/"&gt;Prototype&lt;/a&gt; library, which includes many useful JavaScript functions and comes with  inbuilt Ajax support. If you want to know more about this library, have  a look at the following tutorial: &lt;a href="http://www.sergiopereira.com/articles/prototype.js.html"&gt;"Using prototype.js v1.3.1"&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;In  this first part of the series I will show you how to create a really  basic chat script, and nothing more. In the next parts we'll be adding  more features, eventually creating a really robust and powerful chat  script.&lt;/p&gt;&lt;br /&gt;&lt;h3&gt;How it works&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;Our chat script will consist of two parts: a server and a client.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The  client is used by your visitors, and doesn't contain any PHP at all.  The client must do all the data sending. Every time the user wants to  send a new message, the client must send this data (using Ajax) to the  server. The client must also check for new messages on the server,  again using an Ajax request.&lt;/p&gt;&lt;br /&gt;The server only has to add a new  message or send a list of messages to the client, and it doesn't have  to use any HTML or JavaScript at all. It's strictly PHP. I've added a  simple diagram below to show what I've just&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_QjAQxhBh3Q4/SKw1tGuz1LI/AAAAAAAABOg/IN8CczmRZnM/s1600-h/flowchart.jpg"&gt;&lt;img src="http://2.bp.blogspot.com/_QjAQxhBh3Q4/SKw1tGuz1LI/AAAAAAAABOg/IN8CczmRZnM/s400/flowchart.jpg" alt="" id="BLOGGER_PHOTO_ID_5236619515742377138" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;   &lt;div&gt;&lt;br /&gt;&lt;br /&gt;       &lt;h3&gt;Creating the server&lt;/h3&gt;&lt;br /&gt;     Let's start by creating the server, but first, create a new datebase&lt;a id="KonaLink0" target="_top" href="http://www.phpit.net/article/creating-chat-script-ajax-php-part1/2/#"&gt; &lt;/a&gt; to hold the messages of your chat script, with the following database scheme:&lt;br /&gt;&lt;br /&gt;      &lt;br /&gt;&lt;br /&gt;     CREATE TABLE `message` (&lt;br /&gt;&lt;br /&gt;       `messageid` int(5) NOT NULL AUTO_INCREMENT,&lt;br /&gt;&lt;br /&gt;       `user` varchar(255) NOT NULL DEFAULT '',&lt;br /&gt;&lt;br /&gt;       `message` text NOT NULL,&lt;br /&gt;&lt;br /&gt;       `datetimestamp` int(11) NOT NULL DEFAULT '0',&lt;br /&gt;&lt;br /&gt;       PRIMARY KEY  (`messageid`)&lt;br /&gt;&lt;br /&gt;     ) TYPE=MyISAM AUTO_INCREMENT=1 ;&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;     The first thing the server must do is check what the client wants:  adding a new message or requesting latest messages? The following code  does what we want:&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;     &lt;div&gt;if (!isset($_GET['action'])) {&lt;br /&gt;&lt;br /&gt;               die('This chat server can only be used by the chat client.');&lt;br /&gt;&lt;br /&gt;       }&lt;br /&gt;       &lt;p&gt;$action = $_GET['action'];&lt;br /&gt;&lt;br /&gt;         if ($action != 'get' AND $action != 'add') { $action = 'get'; }&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;// Do we want to get chat messages or add a new message?&lt;br /&gt;&lt;br /&gt;         if ($action == 'get') {&lt;br /&gt;&lt;br /&gt;                 // Get messages&lt;br /&gt;&lt;br /&gt;                 send_messages();&lt;br /&gt;&lt;br /&gt;         } else {&lt;br /&gt;&lt;br /&gt;                 // Add a new message&lt;br /&gt;&lt;br /&gt;                 add_message();&lt;br /&gt;&lt;br /&gt;         }&lt;/p&gt;&lt;br /&gt;     &lt;/div&gt;&lt;br /&gt;     &lt;p&gt;As you can see we're going to use two different functions:  send_messages() to return all the latest messages and add_message() to  add a new message.&lt;/p&gt;&lt;br /&gt;     &lt;p&gt;Adding a new message is quite simple, and it only requires some standard database code, like this:&lt;/p&gt;&lt;br /&gt;     &lt;div&gt;function add_message() {&lt;br /&gt;&lt;br /&gt;               global $db;&lt;br /&gt;       &lt;p&gt;        // Everything there?&lt;br /&gt;&lt;br /&gt;                 if (!isset($_GET['user'])) {&lt;br /&gt;&lt;br /&gt;                         die('error:no-user');&lt;br /&gt;&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt;                        &lt;br /&gt;&lt;br /&gt;                 if (!isset($_GET['message'])) {&lt;br /&gt;&lt;br /&gt;                         die('error:no-message');&lt;br /&gt;&lt;br /&gt;                 }&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;        $user = ss(htmlentities(strip_tags($_GET['user'])));&lt;br /&gt;&lt;br /&gt;                 $message = ss(htmlentities(strip_tags($_GET['message'])));&lt;br /&gt;&lt;br /&gt;                 $datetimestamp = time();&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;        // Insert message&lt;br /&gt;&lt;br /&gt;                 $db-&amp;gt;query ("INSERT INTO message (user, message, datetimestamp) VALUES ('$user', '$message', $datetimestamp)");&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;        // Return any new message&lt;br /&gt;&lt;br /&gt;                 send_messages();&lt;br /&gt;&lt;br /&gt;         }&lt;/p&gt;&lt;br /&gt;     &lt;/div&gt;&lt;br /&gt;     &lt;p&gt;The function first checks if both variables are there, and if  they're not, it returns an error. The errors look a bit weird, but this  format actually makes it easier for our client (you'll see why later).  When everything is okay, the message is inserted into the database.&lt;/p&gt;&lt;br /&gt;     &lt;p&gt;The send_messages() function has to send the messages that have NOT  yet been received by the client. To do this, the client sends the  timestamp of the last received message, from which the server can  automatically select the messages that haven't been received yet, like  so:&lt;/p&gt;&lt;br /&gt;     &lt;div&gt;function send_messages() {&lt;br /&gt;&lt;br /&gt;               global $db;&lt;br /&gt;       &lt;p&gt;        // Is there a latest timestamp?&lt;br /&gt;&lt;br /&gt;                 if (!isset($_GET['latest'])) {&lt;br /&gt;&lt;br /&gt;                         $latest = false;&lt;br /&gt;&lt;br /&gt;                 } else {&lt;br /&gt;&lt;br /&gt;                         $latest = intval($_GET['latest']);&lt;br /&gt;&lt;br /&gt;                 }&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;        // If there isn't a latest, get the five newest messages, and return them&lt;br /&gt;&lt;br /&gt;                 if ($latest == false) {&lt;br /&gt;&lt;br /&gt;                         $messages = $db-&amp;gt;sql_query ("SELECT user, message, datetimestamp FROM message ORDER BY datetimestamp DESC LIMIT 0,4");&lt;br /&gt;&lt;br /&gt;                 } else {&lt;br /&gt;&lt;br /&gt;                         $messages = $db-&amp;gt;sql_query ("SELECT user, message, datetimestamp FROM message WHERE datetimestamp &amp;gt; $latest ORDER BY datetimestamp DESC LIMIT 0,9");&lt;br /&gt;&lt;br /&gt;                 }&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;        // Any messages?&lt;br /&gt;&lt;br /&gt;                 if ($messages == false) {&lt;br /&gt;&lt;br /&gt;                         die('no-messages');&lt;br /&gt;&lt;br /&gt;                 }&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;        // Get newest timestamp&lt;br /&gt;&lt;br /&gt;                 $newest = $messages['0']['datetimestamp'];&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;        // Reverse array for correct order&lt;br /&gt;&lt;br /&gt;                 $messages = array_reverse($messages);&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;        // Return response&lt;br /&gt;&lt;br /&gt;                 $response = $newest;&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;        foreach ($messages as $message) {&lt;br /&gt;&lt;br /&gt;                         $response .= $message['user'] . '&amp;gt;' . $message['message'] . "\n";&lt;br /&gt;&lt;br /&gt;                 }&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;        $response = trim($response);&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;        die($response);&lt;br /&gt;&lt;br /&gt;         }&lt;/p&gt;&lt;br /&gt;     &lt;/div&gt;&lt;br /&gt;     &lt;p&gt;This code first selects the right messages, and after that returns  it in the right format (each message is separated by a newline, and the  user and message are separated by &amp;gt;).&lt;/p&gt;&lt;br /&gt;     &lt;h3&gt;Creating the client&lt;/h3&gt;&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;     &lt;p&gt;You can close your PHP editor now, and switch to your HTML/JS editor, as we'll only be using HTML and JavaScript from now on.&lt;/p&gt;&lt;br /&gt;     &lt;p&gt;First of all, the client page itself. It's nothing advanced, and very simple: &lt;/p&gt;&lt;br /&gt;     &lt;div&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&lt;br /&gt;               &amp;lt;head&amp;gt;&lt;br /&gt;&lt;br /&gt;                       &amp;lt;title&amp;gt;Ajax Chat Client&amp;lt;/title&amp;gt;&lt;br /&gt;       &lt;p&gt;                &amp;lt;script type="text/javascript" src="../prototype.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;                         &amp;lt;script type="text/javascript" src="script.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;                &amp;lt;link REL="stylesheet" HREF="../style.css" TYPE="text/css" media="all"&amp;gt;&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;        &amp;lt;/head&amp;gt;&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;        &amp;lt;body&amp;gt;&amp;lt;div id="container"&amp;gt;&lt;br /&gt;&lt;br /&gt;                         &amp;lt;h1&amp;gt;Ajax Chat Client&amp;lt;/h1&amp;gt;&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;                &amp;lt;div id="login"&amp;gt;&lt;br /&gt;&lt;br /&gt;                                 &amp;lt;p&amp;gt;Please enter an username: &amp;lt;/p&amp;gt;&lt;br /&gt;&lt;br /&gt;                                 &amp;lt;input type="text" name="user" id="user" /&amp;gt;&lt;br /&gt;&lt;br /&gt;                                 &amp;lt;input type="button" onclick="login();" value="Enter Chatroom" /&amp;gt;&lt;br /&gt;&lt;br /&gt;                         &amp;lt;/div&amp;gt;&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;                &amp;lt;div id="chatelements" style="display:none;"&amp;gt;&lt;br /&gt;&lt;br /&gt;                                 &amp;lt;textarea id="chat" rows="20"&amp;gt;&amp;lt;/textarea&amp;gt;&lt;br /&gt;&lt;br /&gt;                                 &amp;lt;input type="text" id="message"&amp;gt;&amp;lt;input type="button" onclick="send_message();" value="Send" /&amp;gt;&lt;br /&gt;&lt;br /&gt;                         &amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;                        &lt;br /&gt;&lt;br /&gt;                         &amp;lt;div id="debug"&amp;gt;&lt;br /&gt;&lt;br /&gt;                         &amp;lt;/div&amp;gt;&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;                 &amp;lt;div id="copyright"&amp;gt;&lt;br /&gt;&lt;br /&gt;                                 This is a demo of an article series on &amp;lt;a href="http://www.phpit.net"&amp;gt;PHPit&amp;lt;/a&amp;gt;.&lt;br /&gt;&lt;br /&gt;                                 Copyright &amp;amp;copy; 2006 Dennis Pallett.&lt;br /&gt;&lt;br /&gt;                         &amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;                 &amp;lt;/div&amp;gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&lt;br /&gt;         &amp;lt;/html&amp;gt;&lt;/p&gt;&lt;br /&gt;     &lt;/div&gt;&lt;br /&gt;     &lt;p&gt;It has three important elements: the login div, which shows a login  box when first viewing the page, a textarea, which is used to show all  the chat messages, and a text field which is used to enter new messages.&lt;/p&gt;&lt;br /&gt;     &lt;p&gt;If you have a close look at the HTML above, you'll notice two  different JS functions: login() and send_message(). These are defined  in the script.js file, and are the most important of our chat script.&lt;/p&gt;&lt;br /&gt;     &lt;p&gt;The login() function is used to set a user's username, and getting the initial messages. It looks like this:&lt;/p&gt;&lt;br /&gt;     &lt;div&gt;var server = 'http://projects/phpit/content/creating%20an%20ajax-based%20chat/demos/1/chatserver.php';&lt;br /&gt;       &lt;p&gt;var username = '';&lt;br /&gt;&lt;br /&gt;         var latest = '';&lt;br /&gt;&lt;br /&gt;         function login() {&lt;br /&gt;&lt;br /&gt;                 // Get username&lt;br /&gt;&lt;br /&gt;                 var user = $F('user');&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;        if (user == '') {&lt;br /&gt;&lt;br /&gt;                         alert('Please enter a username before entering the chat room');&lt;br /&gt;&lt;br /&gt;                         return false;&lt;br /&gt;&lt;br /&gt;                 }&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;        username = user;&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;        // Show chat&lt;br /&gt;&lt;br /&gt;                 Element.hide('login');&lt;br /&gt;&lt;br /&gt;                 Element.show('chatelements');&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;        $('chat').value = '';&lt;br /&gt;&lt;br /&gt;                 $('message').value = '';&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;        // Begin getting messages&lt;br /&gt;&lt;br /&gt;                 get_messages();&lt;br /&gt;&lt;br /&gt;                 checker = new PeriodicalExecuter(get_messages, 2);&lt;br /&gt;&lt;br /&gt;         }&lt;/p&gt;&lt;br /&gt;     &lt;/div&gt;&lt;br /&gt;     &lt;p&gt;The first part of the function checks the username. If everything is  okay, the chat elements are shown, and the latest messages are  retrieved using the get_messages() function. The function also creates  a new object, called the PeriodicalExecuter, which is used to check for  new messages every 2 seconds.&lt;/p&gt;&lt;br /&gt;     &lt;p&gt;The get_messages() function is used to retrieve new functions using an Ajax request, like so:&lt;/p&gt;&lt;br /&gt;     &lt;div&gt;function get_messages() {&lt;br /&gt;&lt;br /&gt;               var args = 'action=get&amp;amp;latest=' + latest;&lt;br /&gt;&lt;br /&gt;               var do_ajax = new Ajax.Request(server, {method: 'get', parameters: args, onComplete: handle_response});&lt;br /&gt;&lt;br /&gt;       }&lt;/div&gt;&lt;br /&gt;     &lt;p&gt;The above code uses the Ajax object (included with the Prototype  library) to send a new GET request to the server with two arguments:  action and the timestamp of the latest message received. As you can  see, the onComplete parameter has been set to handle_response, which  means that when the Ajax request is done, the response will be sent to  a function called handle_response().&lt;/p&gt;&lt;br /&gt;     &lt;p&gt;The handle_response() function actually checks the response, and  decides what to do. Remember the responses that we gave in the server?  We're going to use that now, like so:&lt;/p&gt;&lt;br /&gt;     &lt;div&gt;function handle_response(request) {&lt;br /&gt;&lt;br /&gt;               var response = request.responseText;&lt;br /&gt;       &lt;p&gt;        // Error?&lt;br /&gt;&lt;br /&gt;                 if (response == 'error:no-user') {&lt;br /&gt;&lt;br /&gt;                         // No username, show login again&lt;br /&gt;&lt;br /&gt;                         alert('It appears you aren\'t logged in any longer. Please login again');&lt;br /&gt;&lt;br /&gt;                         Element.show('login');&lt;br /&gt;&lt;br /&gt;                         Element.hide('chatelements');&lt;br /&gt;&lt;br /&gt;                         return false;&lt;br /&gt;&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt;                 if (response == 'error:no-message') {&lt;br /&gt;&lt;br /&gt;                         // No username, show login again&lt;br /&gt;&lt;br /&gt;                         alert('You didn\'t send any message. Please try again');&lt;br /&gt;&lt;br /&gt;                         return false;&lt;br /&gt;&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt;                 if (response == 'no-messages'){&lt;br /&gt;&lt;br /&gt;                         // There are no new messages&lt;br /&gt;&lt;br /&gt;                         return false;&lt;br /&gt;&lt;br /&gt;                 }&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;        // We're getting a valid response, first get the latest timestamp&lt;br /&gt;&lt;br /&gt;                 latest = response.substring(0, 10);&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;        // Now get the messages&lt;br /&gt;&lt;br /&gt;                 messages = response.substring(10, response.length);&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;        // Split messages&lt;br /&gt;&lt;br /&gt;                 messages = messages.split('\n');&lt;/p&gt;&lt;br /&gt;       &lt;p&gt;        // Add each message&lt;br /&gt;&lt;br /&gt;                 var chat = $('chat');&lt;br /&gt;&lt;br /&gt;                 for (var i=0; i &amp;lt; messages.length; i++) {&lt;br /&gt;&lt;br /&gt;                         var message = messages[i].split("&amp;gt;");&lt;br /&gt;&lt;br /&gt;                        &lt;br /&gt;&lt;br /&gt;                         chat.value = chat.value + '\n';&lt;br /&gt;&lt;br /&gt;                         chat.value = chat.value + message[0] + ': ' + message[1];&lt;br /&gt;&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt;         }&lt;/p&gt;&lt;br /&gt;     &lt;/div&gt;&lt;br /&gt;     &lt;p&gt;This function first checks whether any errors have been returned.  This only happens when a message has been sent (and not when receiving  messages). After that it checks whether there are any messages.&lt;/p&gt;&lt;br /&gt;     &lt;p&gt;If there are new messages, it parses the new messages (using some  standard string functions), and then adds the new messages to the chat  area. &lt;/p&gt;&lt;br /&gt;     &lt;p&gt;And that's all there is to it. We've now got an almost working chat  script. All that's left is to write the send_message() function.&lt;/p&gt;&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;   &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-6948263977165259592?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/6948263977165259592/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=6948263977165259592' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/6948263977165259592'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/6948263977165259592'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/08/creating-chat-script-with-php-and-ajax.html' title='Creating a chat script with PHP and Ajax'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SKw1tGuz1LI/AAAAAAAABOg/IN8CczmRZnM/s72-c/flowchart.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-4811355053353131416</id><published>2008-08-20T08:11:00.000-07:00</published><updated>2008-08-20T08:16:33.769-07:00</updated><title type='text'>PHP &amp; Security: 3 Example Exploits</title><content type='html'>&lt;h3 style="font-family: arial;"&gt;Introduction&lt;/h3&gt; &lt;p style="font-family: arial;"&gt;One of the most common aspects of programming and scripting is security. Every program or script has to think about security, and each language has certain weak points. Actually, it isn't the language that has weak points - it's the programmer who creates weak points. PHP is no exception to this, and security should be at the top when you're creating a new script, no matter how simple or small the script may be.&lt;/p&gt; &lt;p style="font-family: arial;"&gt;I'm sure you've all read many basic PHP security articles, which include things like filtering user input, beware of XSS attacks, etc. That's why I'm not going to discuss them in this article. If you haven't heard about these things, have a look on &lt;a href="http://www.google.com/search?sourceid=mozclient&amp;amp;ie=utf-8&amp;amp;oe=utf-8&amp;amp;q=php+security"&gt;Google&lt;/a&gt;. Heck, maybe I'll do a basic PHP security article in the near future.&lt;/p&gt; &lt;p style="font-family: arial;"&gt;In this article we're going to look a three different security cases. In each case I will try to explain the exploit, provide a working example, and then suggest possible fixes to prevent you from making the same mistake. Let's get cracking, shall we?&lt;/p&gt; &lt;h3 style="font-family: arial;"&gt;Security Case #1 - E-mail Injection&lt;/h3&gt; &lt;p style="font-family: arial;"&gt;This is one of the neatest PHP exploits I've ever seen, and really requires some knowledge of how e-mail works. This exploit is often used by spammers to use contact forms on your websites to send out massive amounts of spam, without you even knowing. I used to be a victim of this as well, because I didn't even have a clue this existed. There was one thing I noticed though: really weird messages coming through my contact forms, for example:&lt;/p&gt;&lt;p style="font-family: arial;"&gt;&lt;span style="font-weight: bold;"&gt;Example&lt;/span&gt;&lt;/p&gt;&lt;p style="color: rgb(51, 51, 255); font-family: arial;"&gt;aciov@yourdomain.com&lt;br /&gt;Content-Type: multipart/mixed; boundary=\"===============2145621685==\"&lt;br /&gt;MIME-Version: 1.0&lt;br /&gt;Subject: 9afb7555&lt;br /&gt;To: aciov@yourdomain.com&lt;br /&gt;bcc: mhkoch321@aol.com&lt;br /&gt;From: aciov@yourdomain.com  &lt;/p&gt;&lt;p style="color: rgb(51, 51, 255); font-family: arial;"&gt;This is a multi-part message in MIME format.&lt;/p&gt; &lt;p style="color: rgb(51, 51, 255); font-family: arial;"&gt;--===============2145621685==&lt;br /&gt;Content-Type: text/plain; charset=\"us-ascii\"&lt;br /&gt;MIME-Version: 1.0&lt;br /&gt;Content-Transfer-Encoding: 7bit&lt;/p&gt; &lt;p style="color: rgb(51, 51, 255); font-family: arial;"&gt;wpbtizuum&lt;br /&gt;--===============2145621685==--&lt;/p&gt;&lt;p style="color: rgb(51, 51, 255); font-family: arial;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="font-family: arial;"&gt;As you can see this doesn't make much sense at all. But what it does mean is that spammers are trying to see if your contact form is open to e-mail injection. &lt;/p&gt; &lt;p style="font-family: arial;"&gt;This exploit works quite like SQL injection - untrusted users are able to inject data, because of poor input validation. When you use the &lt;a href="http://php.net/mail"&gt;mail()&lt;/a&gt; function you might think each argument is a separate thing, and they can't influence each other. But that's not the case, and the e-mail is actually one big long text message. For example, mail('me@example.com', 'My Subject', 'My Message', "From: contact@example.com\r\n";) is actually changed into:&lt;/p&gt; &lt;div style="font-family: arial;" class="regcode"&gt;To: me@example.com&lt;br /&gt;Subject: My Subject&lt;br /&gt;From: contact@example.com &lt;p&gt;My Message&lt;/p&gt;&lt;/div&gt; &lt;p style="font-family: arial;"&gt;The exploit happens when spammers are able to insert data into the e-mail, therefore being able to change the complete e-mail. For example, if your mail() function looks like this:&lt;/p&gt; &lt;div style="font-family: arial;" class="phpcode"&gt;&lt;span class="kw2"&gt;&lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span class="re0"&gt;$email&lt;/span&gt; = &lt;span class="re0"&gt;$_POST&lt;/span&gt;&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;'email'&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt;;&lt;br /&gt;&lt;span class="kw3"&gt;mail&lt;/span&gt; &lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="st0"&gt;'me@example.com'&lt;/span&gt;, &lt;span class="st0"&gt;'My Subject'&lt;/span&gt;, &lt;span class="st0"&gt;'My Message'&lt;/span&gt;, &lt;span class="st0"&gt;"From: $email&lt;span class="es0"&gt;\\&lt;/span&gt;r&lt;span class="es0"&gt;\\&lt;/span&gt;n"&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;span class="kw2"&gt;?&gt;&lt;/span&gt;&lt;/div&gt; &lt;p style="font-family: arial;"&gt;As you can see an attacker can inject raw data into the e-mail. This means it's now possible to send a complete different e-mail with a new subject, message, and to header. Your contact form is used as an open relay!&lt;/p&gt;&lt;p style="font-family: arial;"&gt;&lt;strong&gt;How do you protect against this exploit?&lt;/strong&gt;&lt;br /&gt;Easy - validate ALL input, and insert as little as possible into the e-mail. If you make sure you only get valid data from the user, the chance of e-mail injection has already been reduced hugely, and it probably won't be possibly any longer. Also see the above link for different solutions.&lt;br /&gt;&lt;/p&gt;&lt;p style="font-family: arial;"&gt;This is one of the sneakiest exploits around, but it is also very simple (and easy to forget about it as a developer!). The View Source exploit was the one that caused APNIPHP to be "hacked" &lt;a href="http://www.phpit.net/articles/hacked"&gt;&lt;/a&gt; recently.&lt;/p&gt;&lt;p style="font-family: arial;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="font-family: arial;"&gt;It only works when you use a script to highlight or show the source of other PHP files, using the &lt;a href="http://php.net/highlight_file"&gt;highlight_file()&lt;/a&gt; function or the &lt;a href="http://php.net/fopen"&gt;fopen()&lt;/a&gt; function. These functions allow your visitors to view the source of other files, which is the whole point of this script. But you must also implement some security measures to prevent users from viewing files that they shouldn't see (such as database files, password files, etc). The best way of doing this is using a white-list array of filenames, and only allowing these files to be opened. This method is bullet-proof and will never fail.&lt;/p&gt; &lt;p style="font-family: arial;"&gt;But perhaps you want to restrict the script to only allow files from a certain directory, e.g. the 'demos' directory. To enforce this restriction, you'd probably use code like this:&lt;/p&gt; &lt;div style="color: rgb(204, 0, 0); font-family: arial;" class="phpcode"&gt;&lt;span class="kw1"&gt;if&lt;/span&gt; &lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="kw3"&gt;strpos&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="re0"&gt;$file&lt;/span&gt;, &lt;span class="st0"&gt;'demos'&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; === &lt;span class="kw2"&gt;false&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span class="kw3"&gt;echo&lt;/span&gt; &lt;span class="st0"&gt;'Security alert. Not a demo!'&lt;/span&gt;;&lt;br /&gt;&lt;span class="br0"&gt;}&lt;/span&gt; &lt;span class="kw1"&gt;else&lt;/span&gt; &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span class="kw3"&gt;highlight_file&lt;/span&gt; &lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="re0"&gt;$file&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;span class="br0"&gt;}&lt;/span&gt;&lt;/div&gt; &lt;p style="font-family: arial;"&gt;This checks whether the filename contains 'demos', and if so, displays the source. Seems fairly fail-proof, but that's where the exploit strikes. An attacker could include '..' in the filename, which means "go a directory up". So C:\program files\demos\..\ means the same as C:\program files\. This basically means that an attacker has unlimited access to everything on the server. Big whoops!&lt;/p&gt;&lt;p style="font-family: arial;"&gt;&lt;strong&gt;How do you protect against this exploit?&lt;/strong&gt;&lt;br /&gt;The easiest way is to check if the filename contains the two dots and display an error. So the above code becomes:&lt;/p&gt;&lt;div style="color: rgb(204, 0, 0); font-family: arial;" class="phpcode"&gt;&lt;span class="kw1"&gt;if&lt;/span&gt; &lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="kw3"&gt;strpos&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="re0"&gt;$file&lt;/span&gt;, &lt;span class="st0"&gt;'demos'&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; === &lt;span class="kw2"&gt;false&lt;/span&gt; OR &lt;span class="kw3"&gt;strpos&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="re0"&gt;$file&lt;/span&gt;, &lt;span class="st0"&gt;'..'&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; !== &lt;span class="kw2"&gt;false&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span class="kw3"&gt;echo&lt;/span&gt; &lt;span class="st0"&gt;'Security alert. Not a demo!'&lt;/span&gt;;&lt;br /&gt;&lt;span class="br0"&gt;}&lt;/span&gt; &lt;span class="kw1"&gt;else&lt;/span&gt; &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span class="kw3"&gt;highlight_file&lt;/span&gt; &lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="re0"&gt;$file&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;span class="br0"&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;strong style="color: rgb(0, 0, 0);"&gt;UPDATE: &lt;/strong&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; The above way isn't completely secury, and any file that contains 'demos' in the filename can still be viewed. If you really want to secure your view source script, don't allow a full path, and instead only allow a name. For example, instead of using '/home/phpit/public_html/demo/demo.php' simply use 'demo.php', and in your script add the full path. The only thing you have to worry about then is to filter out the two dots, and that's easy.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="phpcode"&gt;&lt;span class="re0"&gt;$file&lt;/span&gt; = &lt;span class="st0"&gt;'/home/phpit/public_html/demo/'&lt;/span&gt; . &lt;span class="re0"&gt;$_GET&lt;/span&gt;&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;'filename'&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt;; &lt;p&gt;&lt;span class="kw1"&gt;if&lt;/span&gt; &lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="kw3"&gt;strpos&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="re0"&gt;$file&lt;/span&gt;, &lt;span class="st0"&gt;'..'&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; !== &lt;span class="kw2"&gt;false&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span class="kw3"&gt;echo&lt;/span&gt; &lt;span class="st0"&gt;'Security alert. Not a demo!'&lt;/span&gt;;&lt;br /&gt;&lt;span class="br0"&gt;}&lt;/span&gt; &lt;span class="kw1"&gt;else&lt;/span&gt; &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span class="kw3"&gt;highlight_file&lt;/span&gt; &lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="re0"&gt;$file&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;span class="br0"&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p style="color: rgb(0, 0, 0);"&gt;This would probably be enough to protect your view source script, and stop this exploit from working. You can also use dedicated source-viewing scripts, like &lt;a href="http://sourceforge.net/projects/phpviewsource"&gt;phpViewSource&lt;/a&gt;.&lt;br /&gt;&lt;/p&gt;&lt;p style="color: rgb(0, 0, 0);"&gt;&lt;strong&gt;How do you protect against this exploit?&lt;/strong&gt;&lt;br /&gt;Protecting your scripts against CSRF attacks is extremely hard to do, and a really dedicated attacker will likely succeed anyway. But there are still steps you can take to make it harder.&lt;/p&gt; &lt;p style="color: rgb(0, 0, 0);"&gt;First of all, make sure that any forms that change data (add/edit/delete) are POST only. GET requests should not be able to change anything.&lt;/p&gt; &lt;p style="color: rgb(0, 0, 0);"&gt;Secondly, include a secret token with your forms, which also expire after a certain period of time. This will prevent almost any kind of CSRF attack, and is extremely different to counter.&lt;/p&gt; &lt;p style="color: rgb(0, 0, 0);"&gt;Finally, don't worry too much about CSRF attacks. Although they are out there, it's likely you won't ever have to deal with it, and even so, it's an easy fix. If you're interested have a look on &lt;a href="http://www.squarefree.com/securitytips/web-developers.html#CSRF"&gt;http://www.squarefree.com/securitytips/web-developers.html#CSRF&lt;/a&gt; for more information about CSRF attacks.&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-4811355053353131416?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/4811355053353131416/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=4811355053353131416' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/4811355053353131416'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/4811355053353131416'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/08/php-security-3-example-exploits.html' title='PHP &amp; Security: 3 Example Exploits'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-4015352314378501738</id><published>2008-08-20T08:08:00.000-07:00</published><updated>2008-08-20T08:10:12.329-07:00</updated><title type='text'>PHP Global Variables</title><content type='html'>&lt;span style="font-weight: bold; font-family: arial;"&gt;Introduction&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Whenever you're developing a new large-scale PHP script, you're bound to use global variables, since some data needs to be used by multiple parts of your script. Good examples of global data are script settings, database connections, user credentials and more. There are many ways of making this data global, but the most commonly used way is to use the global keyword, which we will explore later on in this article.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The only problem with the global keyword, and any global data for that matter, is that's it's actually a very bad way of programming, and usually tends to lead to bigger problems later on. The reason for this is that global data ties all the separate parts of your script together, and often if you make a change in one part, something else will break in another part. If you have more than a few global variables, you're whole script will eventually become a big kludge of unmaintainable code.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;That's why this article will show you how to prevent this by using various techniques and design patterns. But first, let's have a look at the global keyword and how it works.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3 style="font-family: arial;"&gt;Using globals and the global keyword&lt;/h3&gt;&lt;span style="font-family: arial;"&gt;By default PHP defines a few variables called Superglobals which are automatically global, and can be accessed anywhere, like the $_GET or $_REQUEST variables. These are mainly used to retrieve form data or other outside data, and there's no real harm in using these variables, since they should never be written to anyway. But you can also use your own global variables, with the global keyword which is used to import variables from the global scope into the local scope of a function.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The following example demonstrates use of the global keyword:&lt;/span&gt;&lt;br /&gt;&lt;div style="color: rgb(255, 0, 0); font-family: arial;" class="phpcode"&gt;&lt;span class="kw2"&gt;&lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span class="re0"&gt;$my_var&lt;/span&gt; = &lt;span class="st0"&gt;'Hello World'&lt;/span&gt;; &lt;p&gt;test_global&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;;&lt;/p&gt; &lt;p&gt;&lt;span class="kw2"&gt;function&lt;/span&gt; test_global&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span class="co1"&gt;// Now in local scope&lt;/span&gt;&lt;br /&gt;        &lt;span class="co1"&gt;// the $my_var variable doesn't exist&lt;/span&gt;&lt;/p&gt; &lt;p&gt;        &lt;span class="co1"&gt;// Produces error: "Undefined variable: my_var"&lt;/span&gt;&lt;br /&gt;        &lt;span class="kw3"&gt;echo&lt;/span&gt; &lt;span class="re0"&gt;$my_var&lt;/span&gt;;&lt;/p&gt; &lt;p&gt;        &lt;span class="co1"&gt;// Now let's important the variable&lt;/span&gt;&lt;br /&gt;        &lt;span class="kw3"&gt;global&lt;/span&gt; &lt;span class="re0"&gt;$my_var&lt;/span&gt;;&lt;/p&gt; &lt;p&gt;        &lt;span class="co1"&gt;// Works:&lt;/span&gt;&lt;br /&gt;        &lt;span class="kw3"&gt;echo&lt;/span&gt; &lt;span class="re0"&gt;$my_var&lt;/span&gt;;&lt;br /&gt;&lt;span class="br0"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="kw2"&gt;?&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;p style="font-family: arial;"&gt;As you can see in the above example, the global keyword is used to important variables from the global scope. Seems to work fine, and it's nice and simple, so why should you worry about using the global keyword?&lt;/p&gt; &lt;p style="font-family: arial;"&gt;There are three good reasons:&lt;/p&gt; &lt;p style="font-family: arial;"&gt;&lt;strong&gt;1. Reusing parts of the script is impossible&lt;/strong&gt;&lt;br /&gt;If a certain function relies on global variables, it becomes almost impossible to use that function in a different context. Another problem is that you can't take that function, and use it in another script.&lt;/p&gt; &lt;p style="font-family: arial;"&gt;&lt;strong&gt;2. Solving bugs is much harder&lt;/strong&gt;&lt;br /&gt;Tracking a global variable is much harder than a non-global variable. A global variable could be declared in some obscure include file, which could take hours to find, although a good text editor / IDE could help with this.&lt;/p&gt; &lt;p style="font-family: arial;"&gt;&lt;strong&gt;3. Understanding the code in a year will be much more difficult&lt;/strong&gt;&lt;br /&gt;Globals make it difficult to see where a variable is coming from and what it does. You might know about every global during development, but after a year or so you'll probably have forgotten at least half of them, and then you'll be kicking yourself for using so many globals.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-4015352314378501738?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/4015352314378501738/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=4015352314378501738' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/4015352314378501738'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/4015352314378501738'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/08/php-global-variables.html' title='PHP Global Variables'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-4942194576858585733</id><published>2008-08-20T08:01:00.000-07:00</published><updated>2008-08-20T08:02:22.709-07:00</updated><title type='text'>Google tips and tricks- Google don'ts</title><content type='html'>&lt;strong style="font-family: arial;"&gt;Google tips: &lt;/strong&gt; &lt;p style="font-family: arial;"&gt;Bellow                      are some techniques which may reduce your Google ranking or                      even ban you from its index. You should avoid them if possible.&lt;/p&gt;                   &lt;p style="font-family: arial;"&gt;&lt;strong&gt;Bad navigation&lt;br /&gt;                    &lt;/strong&gt;&lt;br /&gt;                    Your website must have clean and simple navigation. This way                      you ensure that Googlebot will be able to crawl your entire                      site. Navigation links should be located near the top of the                      pages since this makes it easy for your visitors and Googlebot                      to navigate through your site.&lt;br /&gt;                    Best bet for navigation is use of text links, as this increases                      word count and keyword density, as well as giving description                      of destination page to Googlebot. Googlebot is also able to                      follow image links and from recently Flash navigation links.                      If you use image links make sure you add some description                      in “alt” attribute of image tag to describe your                      link.&lt;/p&gt;                   &lt;p style="font-family: arial;"&gt;&lt;strong&gt;JavaScript links&lt;/strong&gt;&lt;br /&gt;                   &lt;br /&gt;                    Googlebot is not able (currently) to follow JavaScript links.                      People often use these type of links for fancy navigation.                      If you use them just make sure you have alternative navigation                      using HTML links.&lt;/p&gt;                   &lt;p style="font-family: arial;"&gt;&lt;strong&gt;Hidden text&lt;/strong&gt;&lt;br /&gt;                   &lt;br /&gt;                    Googlebot and other robots learned to recognize this method                      several years ago. So if you don’t want to be identified                      as spammer and banned from SERP’s, don’t use this                      method. &lt;/p&gt;                   &lt;p style="font-family: arial;"&gt;&lt;strong&gt;Hidden links&lt;/strong&gt;&lt;br /&gt;                   &lt;br /&gt;                    Number of incoming links to certain page has direct effect                      to Google PageRank (PR). However, if those are hidden that                      may produce similar results as with hidden text.&lt;/p&gt;                   &lt;p style="font-family: arial;"&gt;&lt;strong&gt;Cloaking&lt;/strong&gt;&lt;br /&gt;                   &lt;br /&gt;                    Cloaking is a search engine optimization method where you                      serve highly optimized page version to robots and a regular                      page to your visitors. Official Google policy is that cloaked                      pages will not be allowed in their index. However, there are                      many websites that use cloaking with great success. So if                      you like to risk getting banned from SERP’s you may                      use this method, just make sure you do it properlyJ&lt;/p&gt;                   &lt;p style="font-family: arial;"&gt;&lt;strong&gt;Guest book spamming and FFA pages&lt;/strong&gt;&lt;br /&gt;                   &lt;br /&gt;                    Adding your link to hundreds of guest books will not help                      you with your PR, since it appears that Google is able to                      detect them and ignores outgoing links completely. This way                      you’ll save yourself many hours of useless work.&lt;br /&gt;                    When PR was initially introduced, many SEO companies were                      offering to “submit your site to zillion FFA pages for                      free” and hopefully increase your PR. I don’t                      remember that this used to work at time and it certainly doesn’t                      work now. If you find any of these, avoid them.&lt;/p&gt;                   &lt;strong style="font-family: arial;"&gt;Sessions&lt;/strong&gt;&lt;br /&gt;                     &lt;br /&gt;&lt;span style="font-family: arial;"&gt;                     Google is not able to accept session cookies and will try                      avoiding URL based sessions. Also, you should use fewer parameters                      in you dynamic URLs and avoid use “id” parameter                      as Googlebot may think that is session ID.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-4942194576858585733?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/4942194576858585733/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=4942194576858585733' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/4942194576858585733'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/4942194576858585733'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/08/google-tips-and-tricks-google-donts.html' title='Google tips and tricks- Google don&apos;ts'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-5577182546425152442</id><published>2008-08-20T07:57:00.000-07:00</published><updated>2008-08-20T08:01:10.376-07:00</updated><title type='text'>Simple Mini Poll class library</title><content type='html'>&lt;span style="font-family: arial;"&gt;This easy-to-use class library enables you to set up your own                    survey system in just few minutes.&lt;/span&gt;&lt;br /&gt; &lt;br /&gt; &lt;span style="font-family: arial;" class="fat"&gt;Main                    features include:&lt;/span&gt; &lt;ul style="font-family: arial;"&gt;&lt;li&gt; Dynamically generated form (with number of total votes)&lt;/li&gt;&lt;li&gt;Detailed result page&lt;/li&gt;&lt;li&gt;View of old polls&lt;/li&gt;&lt;li&gt;Poll administration interface&lt;/li&gt;&lt;li&gt;Check for repeated votes&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-family: arial;"&gt;1 . Execute these queries on your database:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;code style="font-family: arial;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;# Table structure for table `poll_check`&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;CREATE TABLE &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;`&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;poll_check&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;` (&lt;br /&gt;  `&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;pollid&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;` &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;11&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;NOT NULL &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;default &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'0'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;  `&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;ip&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;` &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;varchar&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;20&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;NOT NULL &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;default &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;''&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;  `&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;time&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;` &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;varchar&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;14&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;NOT NULL &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;default &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;''&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;TYPE&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;MyISAM COMMENT&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;''&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;# -----------------------------------------&lt;br /&gt;&lt;br /&gt;# Table structure for table `poll_data`&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;CREATE TABLE &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;`&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;poll_data&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;` (&lt;br /&gt;  `&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;pollid&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;` &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;11&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;NOT NULL &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;default &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'0'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;  `&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;polltext&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;` &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;varchar&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;50&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;NOT NULL &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;default &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;''&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;  `&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;votecount&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;` &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;11&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;NOT NULL &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;default &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'0'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;  `&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;voteid&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;` &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;11&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;NOT NULL &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;default &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'0'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;  `&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;status&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;` &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;varchar&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;6&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) default &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;NULL&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;TYPE&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;MyISAM COMMENT&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;''&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;# -----------------------------------------&lt;br /&gt;&lt;br /&gt;# Table structure for table `poll_desc`&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;CREATE TABLE &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;`&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;poll_desc&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;` (&lt;br /&gt;  `&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;pollid&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;` &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;11&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;NOT NULL &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;default &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'0'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;  `&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;polltitle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;` &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;varchar&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;100&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;NOT NULL &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;default &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;''&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;  `&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;timestamp&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;` &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;datetime NOT NULL &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;default &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'0000-00-00 00:00:00'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;  `&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;votecount&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;` &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;mediumint&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;9&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;NOT NULL &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;default &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'0'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;  `&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;STATUS&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;` &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;varchar&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;6&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) default &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;NULL&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;PRIMARY KEY &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(`&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;pollid&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;`)&lt;br /&gt;) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;TYPE&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;MyISAM COMMENT&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;''&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;# -----------------------------------------&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-family: arial;"&gt;2. Set up database connection parameters.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;3. Paste this code on page where you wish poll to appear:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;code style="font-family: arial;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;include_once (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"includes/miniPoll.class.php"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$test &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= new &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;miniPoll&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$test&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;pollForm&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-family: arial;"&gt;4. Paste this code on page where you wish poll results to                        appear:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;code style="font-family: arial;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;include_once (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"includes/miniPoll.class.php"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$test &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= new &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;miniPoll&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;if (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_GET&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'poll'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]) &amp;amp;&amp;amp; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;is_numeric&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_GET&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'pollid'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$pollid &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_GET&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'pollid'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;&lt;br /&gt;    if (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_GET&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'voteid'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]) &amp;amp;&amp;amp; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;is_numeric&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_GET&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'voteid'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) {&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$voteid &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_GET&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'voteid'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$test&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;processPoll&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$pollid&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$voteid&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;if (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_GET&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'pollid'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$pollid &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_GET&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'pollid'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$test&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;pollResults&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$pollid&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-family: arial;"&gt;5. Paste this code on poll admin page:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;code style="font-family: arial;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;include_once (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"includes/miniPollAdmin.class.php"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$test &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= new &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;miniPollAdmin&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$test&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;newPollForm&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();&lt;br /&gt;&lt;br /&gt;if (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_GET&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'opt'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$opt &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_GET&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'opt'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$pollid &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_GET&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'pollid'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;    if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$opt &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;== &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'activate'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$test&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;activatePoll&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$pollid&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    }&lt;br /&gt;    if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$opt &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;== &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'delete'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$test&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;deletePoll&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$pollid&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;if (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_GET&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'q'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$pollname &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_GET&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'pollname'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$q &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_GET&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'q'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$test&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;createPoll&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$pollname&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$q&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$test&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;listPolls&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-family: arial;"&gt;6. Set up these parameters in miniPoll.class.php:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;code style="font-family: arial;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php $this&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;results_page &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"test_poll_results.php"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-family: arial;"&gt; page where you display results&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;7. Set up these parameters in miniPollAdmin.class.php:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;code style="font-family: arial;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php $this&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;results_page &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"test_poll_admin.php"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-family: arial;"&gt; name of admin page file&lt;/span&gt;&lt;br /&gt;                       &lt;br /&gt;&lt;span style="font-family: arial;"&gt;8. Optionally you can change layout of form and results page&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;9. Create new poll by starting admin page&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;10. Activate your poll by clicking ACTIVATE&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;11. Enjoy and send me your comments&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-5577182546425152442?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/5577182546425152442/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=5577182546425152442' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/5577182546425152442'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/5577182546425152442'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/08/simple-mini-poll-class-library.html' title='Simple Mini Poll class library'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-1923254444523417980</id><published>2008-08-20T07:49:00.000-07:00</published><updated>2008-08-20T07:56:52.307-07:00</updated><title type='text'>How to create and use Favicon.ico file</title><content type='html'>&lt;span style="font-family: arial;"&gt;&lt;p&gt;What is Favicon.ico?&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;Favicon is a small icon which appears next to your URL in browser address bar.&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;Why would I use it?&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;If you look around the Internet, you will notice that all professional web sites use it. It gives more customized appearance of your site in visitor browser and it also gives more distinct look of your site in Bookmarks menu by replacing generic browser icon.&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;What browsers support it?&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;Currently all modern browsers support it. Including: Internet Explorer, Mozilla Firefox, Opera, Netscape 7.0 and Mozilla.&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;How do I create Favicon?&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;Best solution would be to get some of popular icon editors. If you don't have icon editor, you may use some of the standard image editors like Photoshop, PaintShop or even Windows paint. Simply create 16x16 pixels bitmap image with standard 16 or 256 Windows icon colors. You can't put much in such a small space, but with wright color combinations you may achieve very effective solutions. When you're done editing, simply rename file to favicon.ico.&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;Where do I put Favicon.ico file?&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;Simply use your favorite FTP program and upload it in root folder of your web site. Most browser look there for it. You may also help them by inserting following code in  section of your page:&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(255, 0, 0);"&gt;&lt;p&gt;&amp;lt;link href=&amp;quot;favicon.ico&amp;quot; rel=&amp;quot;SHORTCUT ICON&amp;quot;&amp;gt;&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;This way you ensure that browser will find it. You may also put favicon file in different folder, like for example, in your images folder. In that case code may look like this:&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(255, 0, 0);"&gt;&lt;p&gt;&amp;lt;link href=&amp;quot;images/favicon.ico&amp;quot; rel=&amp;quot;SHORTCUT ICON&amp;quot;&amp;gt;&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-1923254444523417980?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/1923254444523417980/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=1923254444523417980' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/1923254444523417980'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/1923254444523417980'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/08/how-to-create-and-use-faviconico-file.html' title='How to create and use Favicon.ico file'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-2154004374969700783</id><published>2008-08-20T07:38:00.000-07:00</published><updated>2008-08-20T07:47:46.309-07:00</updated><title type='text'>User Online Class</title><content type='html'>&lt;span style="font-family: arial;" class="fat"&gt;Description:&lt;/span&gt;&lt;br /&gt;                     &lt;br /&gt;&lt;span style="font-family: arial;"&gt;                    This very simple class enables you to track number of visitors                    online in an easy and accurate manner.&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;span style="font-family: arial;" class="fat"&gt;Main                    features include:&lt;/span&gt;  &lt;ul style="font-family: arial;"&gt;&lt;li&gt; Automatic insertion of new user&lt;/li&gt;&lt;li&gt;Automatic database cleanup&lt;/li&gt;&lt;li&gt;Check if user is coming behind proxy server (this helps                        in script accuracy)&lt;/li&gt;&lt;li&gt;Display of users online&lt;/li&gt;&lt;li&gt;Error reporting&lt;/li&gt;&lt;/ul&gt; &lt;br /&gt;&lt;code style="font-family: arial;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;span style="font-weight: bold;"&gt;DATABASE STRUCTURE&lt;/span&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;CREATE TABLE &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;`&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;useronline&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;` (&lt;br /&gt;  `&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;id&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;` &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;NOT NULL auto_increment&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;  `&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;ip&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;` &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;varchar&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;15&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;NOT NULL &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;default &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;''&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;  `&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;timestamp&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;` &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;varchar&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;15&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;NOT NULL &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;default &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;''&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;PRIMARY KEY &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(`&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;id&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;`),&lt;br /&gt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;UNIQUE KEY &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;`&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;id&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;`(`&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;id&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;`)&lt;br /&gt;) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;TYPE&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;MyISAM COMMENT&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'' &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;AUTO_INCREMENT&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;PHP CODE :&lt;/span&gt;&lt;br /&gt;&lt;code style="font-family: arial;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;include_once (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"usersOnline.class.php"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$visitors_online &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= new &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;usersOnline&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();&lt;br /&gt;&lt;br /&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;count&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$visitors_online&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;error&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) == &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;&lt;br /&gt;    if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$visitors_online&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;count_users&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;() == &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;        echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"There is " &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$visitors_online&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;count_users&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;() . &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;" visitor online"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    }&lt;br /&gt;    else {&lt;br /&gt;        echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"There are " &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$visitors_online&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;count_users&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;() . &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;" visitors online"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;b&gt;Users online class errors:&lt;/b&gt;&lt;br /&gt;&lt;ul&gt;\r\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    for (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$i &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$i &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&lt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;count&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$visitors_online&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;error&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$i &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;++ ) {&lt;br /&gt;        echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;li&gt;" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$visitors_online&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;error&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$i&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] . &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/li&gt;\r\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    }&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/ul&gt;\r\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt; &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt; &lt;span style="font-family: arial;" class="fat"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-2154004374969700783?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/2154004374969700783/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=2154004374969700783' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/2154004374969700783'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/2154004374969700783'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/08/user-online-class.html' title='User Online Class'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-9221896757529673038</id><published>2008-08-12T12:04:00.003-07:00</published><updated>2008-08-12T12:04:46.173-07:00</updated><title type='text'>PHP Array</title><content type='html'>&lt;span style="font-family: arial;"&gt;An array is a data structure that stores one or more values in a single value. For experienced programmers it is important to note that PHP's arrays are actually maps (each key is mapped to a value). &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;PHP - A Numerically Indexed Array&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If this is your first time seeing an array, then you may not quite understand the concept of an array. Imagine that you own a business and you want to store the names of all your employees in a PHP variable. How would you go about this?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;It wouldn't make much sense to have to store each name in its own variable. Instead, it would be nice to store all the employee names inside of a single variable. This can be done, and we show you how below.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;PHP Code:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;$employee_array[0] = "Bob";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;$employee_array[1] = "Sally";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;$employee_array[2] = "Charlie";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;$employee_array[3] = "Clare";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;In the above example we made use of the key / value structure of an array. The keys were the numbers we specified in the array and the values were the names of the employees. Each key of an array represents a value that we can manipulate and reference. The general form for setting the key of an array equal to a value is:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    * $array[key] = value;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If we wanted to reference the values that we stored into our array, the following PHP code would get the job done.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Note: As you may have noticed from the above code example, an array's keys start from 0 and not 1. This is a very common problem for many new programmers who are used to counting from 1 and lead to "off by 1" errors. This is just something that will take experience before you are fully comfortable with it.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;PHP Code:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;echo "Two of my employees are "&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;. $employee_array[0] . " &amp;amp; " . $employee_array[1]; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;echo "&lt;br /&gt;Two more employees of mine are " &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;. $employee_array[2] . " &amp;amp; " . $employee_array[3];&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Display:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Two of my employees are Bob &amp;amp; Sally&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Two more employees of mine are Charlie &amp;amp; Clare&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;PHP arrays are quite useful when used in conjunction with loops, which we will talk about in a later lesson. Above we showed an example of an array that made use of integers for the keys (a numerically indexed array). However, you can also specify a string as the key, which is referred to as an associative array.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;PHP - Associative Arrays&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;In an associative array a key is associated with a value. If you wanted to store the salaries of your employees in an array, a numerically indexed array would not be the best choice. Instead, we could use the employees names as the keys in our associative array, and the value would be their respective salary.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;PHP Code:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;$salaries["Bob"] = 2000;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;$salaries["Sally"] = 4000;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;$salaries["Charlie"] = 600;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;$salaries["Clare"] = 0;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;echo "Bob is being paid - $" . $salaries["Bob"] . "&lt;br /&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;echo "Sally is being paid - $" . $salaries["Sally"] . "&lt;br /&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;echo "Charlie is being paid - $" . $salaries["Charlie"] . "&lt;br /&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;echo "Clare is being paid - $" . $salaries["Clare"];&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Display:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Bob is being paid - $2000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Sally is being paid - $4000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Charlie is being paid - $600&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Clare is being paid - $0&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Once again, the usefulness of arrays will become more apparent once you have knowledge of for and while loops.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-9221896757529673038?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/9221896757529673038/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=9221896757529673038' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/9221896757529673038'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/9221896757529673038'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/08/php-array.html' title='PHP Array'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-678416944975203825</id><published>2008-08-12T12:04:00.001-07:00</published><updated>2008-08-12T12:04:25.645-07:00</updated><title type='text'>PHP Require</title><content type='html'>&lt;span style="font-family: arial;"&gt;Just like the previous lesson, the require command is used to include a file into your PHP code. However there is one huge difference between the two commands, though it might not seem that big of a deal.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Require vs Include&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;When you include a file with the include command and PHP cannot find it you will see an error message like the following:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;PHP Code:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Display:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Warning: main(noFileExistsHere.php): failed to open stream: No such file or directory in /home/websiteName/FolderName/tizagScript.php on line 2 Warning: main(): Failed opening 'noFileExistsHere.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/websiteName/FolderName/tizagScript.php on line 2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Hello World!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Notice that our echo statement is still executed, this is because a Warning does not prevent our PHP script from running. On the other hand, if we did the same example but used the require statement we would get something like the following example.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;PHP Code:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Display:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Warning: main(noFileExistsHere.php): failed to open stream: No such file or directory in /home/websiteName/FolderName/tizagScript.php on line 2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Fatal error: main(): Failed opening required 'noFileExistsHere.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/websiteName/FolderName/tizagScript.php on line 2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The echo statement was not executed because our script execution died after the require command returned a fatal error! We recommend that you use require instead of include because your scripts should not be executing if necessary files are missing or misnamed.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-678416944975203825?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/678416944975203825/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=678416944975203825' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/678416944975203825'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/678416944975203825'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/08/php-require.html' title='PHP Require'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-8364784099083988125</id><published>2008-08-12T12:03:00.000-07:00</published><updated>2008-08-12T12:04:05.456-07:00</updated><title type='text'>PHP Include</title><content type='html'>&lt;span style="font-family: arial;"&gt;Without understanding much about the details of PHP, you can save yourself a great deal of time with the use of the PHP include command. include takes a file name and simply inserts that file's contents into the script that issued the include command.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Why is this a cool thing? Well, first of all, this means that you can type up a common header or menu file that you want all your web pages to include. When you add a new page to your site, instead of having to update the links on several web pages, you can simply change the Menu file.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;An Include Example&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Say we wanted to create a common menu file that all our pages will use. A common practice for naming files that are to be included is to use the ".php" extension. Since we want to create a common menu let's save it as "menu.php".&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;menu.php Code:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt; html&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt; body&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;a href="http://www.example.com/index.php"&gt;Home&lt;/a&gt; - &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;a href="http://www.example.com/about.php"&gt;About Us&lt;/a&gt; - &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;a href="http://www.example.com/links.php"&gt;Links&lt;/a&gt; - &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;a href="http://www.example.com/contact.php"&gt;Contact Us&lt;/a&gt; &lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Save the above file as "menu.php". Now create a new file, "index.php" in the same directory as "menu.php". Here we will take advantage of the include command to add our common menu.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;index.php Code:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;?php include("menu.php"); ?&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;This is my home page that uses a common menu to save me time when I add&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;new pages to my website!&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt; /body&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt; /html&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;And we would do the same thing for "about.php", "links.php", and "contact.php". Just think how terrible it would be if you had 15 or more pages with a common menu and you decided to add another web page to that site. You would have to go in and manually edit every single file to add this new page, but with include files you simply have to change "menu.php" and all your problems are solved. Avoid such troublesome occasions with a simple include file.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;What do Visitors See?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If we were to use the include command to insert a menu on each of our web pages, what would the visitor see if they viewed the source of "index.php"? Well, because the include command is pretty much the same as copying and pasting, the visitors would see:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;View Source of index.php to a Visitor:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt; html&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt; body&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;a href="index.php"&gt;Home&lt;/a&gt; - &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;a href="about.php"&gt;About Us&lt;/a&gt; - &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;a href="links.php"&gt;Links&lt;/a&gt; - &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;a href="contact.php"&gt;Contact Us&lt;/a&gt; &lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;This is my home page that uses a common menu to save me time when I add&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;new pages to my website!&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt; /body&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt; /html&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The visitor would actually see all the HTML code as one long line of HTML code, because we have not inserted any new line characters. We did some formatting above to make it easier to read. We will be discussing new line characters later.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-8364784099083988125?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/8364784099083988125/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=8364784099083988125' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/8364784099083988125'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/8364784099083988125'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/08/php-include.html' title='PHP Include'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-9173626432428502492</id><published>2008-08-12T12:02:00.002-07:00</published><updated>2008-08-12T12:03:09.288-07:00</updated><title type='text'>Passing JavaScript variables to PHP</title><content type='html'>&lt;span style="font-family: arial;"&gt;JavaScript is mainly used as a client side scripting language, while PHP is a server side technology. Unlike Java or ASP.Net, PHP doesn't have tools to make it work client side. That is why you need to combine JavaScript and PHP scripts to develop powerful web-applications.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;One of the frequent problems is defining visitor’s screen resolution using JavaScript tools and passing this data to PHP-script. The following script provides solution for this problem:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;script type="text/javascript"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;width = screen.width;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;height = screen.height;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;if (width &gt; 0 &amp;amp;&amp;amp; height &gt;0) {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    window.location.href = "http://localhost/main.php?width=" + width + "&amp;amp;height=" + height;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;} else &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    exit();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;/script&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Copy and paste this code snippet in the text editor, save it as index.htm and run it in your browser. After this code has been executed, a user is automatically redirected to the main.php page where screen resolution is displayed in the browser window.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The main.php looks as follows:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;echo "&lt;h1&gt;Screen Resolution:&lt;/h1&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;echo "Width  : ".$_GET['width']."&lt;br /&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;echo "Height : ".$_GET['height']."&lt;br /&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;?&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-9173626432428502492?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/9173626432428502492/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=9173626432428502492' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/9173626432428502492'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/9173626432428502492'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/08/passing-javascript-variables-to-php.html' title='Passing JavaScript variables to PHP'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-6781441546287438441</id><published>2008-08-12T12:02:00.001-07:00</published><updated>2008-08-12T12:02:53.013-07:00</updated><title type='text'>How to Get the Current Page URL in PHP</title><content type='html'>&lt;span style="font-family: arial;"&gt;Sometimes, you might want to get the current page URL that is shown in the browser URL window. For example if you want to let your visitors submit a blog post to Digg you need to get that same exact URL. There are plenty of other reasons as well. Here is how you can do that.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Add the following code to a page:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;function curPageURL() {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt; $pageURL = 'http';&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt; $pageURL .= "://";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt; if ($_SERVER["SERVER_PORT"] != "80") {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt; } else {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt; }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt; return $pageURL;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;?&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;You can now get the current page URL using the line: &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  echo curPageURL();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;?&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Sometimes it is needed to get the page name only. The following example shows how to do it: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;function curPageName() {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt; return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;echo "The current page name is ".curPageName();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;?&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-6781441546287438441?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/6781441546287438441/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=6781441546287438441' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/6781441546287438441'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/6781441546287438441'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/08/how-to-get-current-page-url-in-php.html' title='How to Get the Current Page URL in PHP'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-4541463851158755110</id><published>2008-08-12T12:01:00.000-07:00</published><updated>2008-08-12T12:02:26.790-07:00</updated><title type='text'>PHP: Dynamic Image Generation</title><content type='html'>&lt;span style="font-family: arial;"&gt;Creating images on the fly can be a very useful skill. PHP has some built-in image generation functions, further more, to generate new images or edit existing images on the fly using PHP, we need to have the GD library installed. In this tutorial we will show you how to get quite interesting and useful effects using image handling functions. We will review two practical tasks: creating security images (captcha) on the fly and building a bar chart using numerical values retrieved from MySQL database.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Creating security images on the fly&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;At first, have a look at the following script that creates captcha image. Next, we will consider each step of image generation in details.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;//Send a generated image to the browser&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;create_image();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;exit();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;function create_image()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    //Let's generate a totally random string using md5&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $md5 = md5(rand(0,999)); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    //We don't need a 32 character long string so we trim it down to 5 &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $pass = substr($md5, 10, 5); &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    //Set the image width and height&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $width = 100;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $height = 20; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    //Create the image resource &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $image = ImageCreate($width, $height);  &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    //We are making three colors, white, black and gray&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $white = ImageColorAllocate($image, 255, 255, 255);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $black = ImageColorAllocate($image, 0, 0, 0);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $grey = ImageColorAllocate($image, 204, 204, 204);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    //Make the background black &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ImageFill($image, 0, 0, $black); &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    //Add randomly generated string in white to the image&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ImageString($image, 3, 30, 3, $pass, $white); &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    //Throw in some lines to make it a little bit harder for any bots to break &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ImageRectangle($image,0,0,$width-1,$height-1,$grey); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    imageline($image, 0, $height/2, $width, $height/2, $grey); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    imageline($image, $width/2, 0, $width/2, $height, $grey); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    //Tell the browser what kind of file is come in &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    header("Content-Type: image/jpeg"); &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    //Output the newly created image in jpeg format &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ImageJpeg($image);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    //Free up resources&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ImageDestroy($image);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;?&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;To create a new image or edit an existing one, we need to create image identifier. In the preceding example we created an empty canvas by calling ImageCreate() function, passing it width and height  of a new image as a parameters. Another way to do it is to read the existing image from the file.  Depending on the file format you can do it using one of the following functions: ImageCreateFromPNG(), ImageCreateFromGIF(), ImageCreateFromJPEG(). Parameter of each function is a file name.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Then, we need to choose colors to be used while painting. For this we can use ImageColorAllocate() function and image identifiers for red, green, and blue (RGB) components of necessary color will be passed as parameters.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;On the next step, we will generate our image. First, using ImageFill() function we will create black background.  Parameters of this function are: image identifier, initial coordinates of the area to be filled and fill color.  Then, we will use ImageString() function to add text to the image. Its parameters are – image identifier, font, coordinates for the first text position and text color. Finally, we will draw two lines and a rectangular to protect our image a little bit.  Please note, that the final point of the rectangular has the following coordinates: $width-1 and $height-1. If they were equal to $width and $height, than the rectangular would have exceeded canvas frame.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;When we had created the image, we can output it either to a browser, or to a file. Our example shows how to output it to the browser. We need to inform the browser, that we will output the image, not the text or html-code. To do it, call Header() function, setting image MIME-type. It’s worth mentioning that Header() function can not be executed if HTTP header has already been sent.   After sending the header we can output our image using ImageJpeg() function, passing it image identifier as a parameter.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;When we have finished working with the image we need to free up resources using ImageDestroy() function.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;font-size:180%;" &gt;&lt;span style="font-weight: bold;"&gt;Building a bar chart&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;In the example below, using graphic functions we will build a bar chart based on the values stored in MySQL database. In our case, values represent poll results.&lt;br /&gt;&lt;br /&gt;In this example we will use poll database. To create it run the following SQL script in your MySQL server:&lt;br /&gt;CREATE DATABASE `poll`;&lt;br /&gt;USE poll;&lt;br /&gt;&lt;br /&gt;CREATE TABLE `results` (&lt;br /&gt;   book_type VARCHAR(50),&lt;br /&gt;   num_votes INT&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;INSERT INTO `results` values &lt;br /&gt;    ('Classic', 15),&lt;br /&gt;    ('Fantasy', 7),&lt;br /&gt;    ('Humor', 32),&lt;br /&gt;    ('Mystery', 12),&lt;br /&gt;    ('Poetry', 25);&lt;br /&gt;&lt;br /&gt;Script building a bar chart is quite long, so let's divide it into two parts and discuss them separately. The first part of the script connects to MySQL database and requests data that will be represented in the bar chart.&lt;br /&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;//Querying the database to get poll results&lt;br /&gt;&lt;br /&gt;//connection to the database&lt;br /&gt;$dbhandle = mysql_connect("localhost", "root", "")&lt;br /&gt;  or die("Unable to connect to MySQL");&lt;br /&gt;&lt;br /&gt;//select a database to work with&lt;br /&gt;$selected = mysql_select_db("poll",$dbhandle)&lt;br /&gt;  or die("Could not select examples");&lt;br /&gt;&lt;br /&gt;//execute the SQL query and return records&lt;br /&gt;$result = mysql_query("SELECT * FROM results");&lt;br /&gt;&lt;br /&gt;$num_poller = mysql_num_rows($result);&lt;br /&gt;$total_votes = 0;&lt;br /&gt;&lt;br /&gt;//fetch the data from the database&lt;br /&gt;while ($row = mysql_fetch_array($result)) {&lt;br /&gt;  $total_votes += $row{'num_votes'};  //calculating total number of votes&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//nulling the pointer $result&lt;br /&gt;mysql_data_seek($result,0);&lt;br /&gt;&lt;br /&gt;//close the connection&lt;br /&gt;mysql_close($dbhandle);&lt;br /&gt;&lt;br /&gt;In the second part of the script first of all we will calculate variables needed to build the chart. Then, we prepare primary image and actually output data. Results for each genre are picked from the database one by one, percentage of votes is calculated, and then bars and explanatory notes are outputted.&lt;br /&gt;&lt;br /&gt;In this script we are using TrueType fonts to get anti-aliased text. Functions that work with the TrueType fonts have its own peculiarities. First, you need to point where the fonts are located. For this, system variable GDFONTPATH is set. Then, we need to set the font name. TrueType fonts are rendered using  ImageTTFText().&lt;br /&gt;&lt;br /&gt;We have already discussed above all functions used for drawing, the code has been commented and is quite clear, so you shouldn’t have any trouble.&lt;br /&gt;&lt;br /&gt;//Tell gd2, where your fonts reside&lt;br /&gt;putenv('GDFONTPATH=C:\WINDOWS\Fonts');&lt;br /&gt;$font = 'arial';&lt;br /&gt;&lt;br /&gt;//Set starting point for drawing&lt;br /&gt;$y = 50;&lt;br /&gt;&lt;br /&gt;//Specify constant values&lt;br /&gt;$width = 700; //Image width in pixels&lt;br /&gt;$bar_height = 20; //Bars height&lt;br /&gt;$height = $num_poller * $bar_height * 1.5 + 70; //Calculating image height&lt;br /&gt;$bar_unit = ($width - 400) / 100; //Distance on the bar chart standing for 1 unit&lt;br /&gt;&lt;br /&gt;//Create the image resource&lt;br /&gt;$image = ImageCreate($width, $height);&lt;br /&gt;&lt;br /&gt;//We are making four colors, white, black, blue and red&lt;br /&gt;$white = ImageColorAllocate($image, 255, 255, 255);&lt;br /&gt;$black = ImageColorAllocate($image, 0, 0, 0);&lt;br /&gt;$red   = ImageColorAllocate($image, 255, 0, 0);&lt;br /&gt;$blue  = imagecolorallocate($image,0,0,255);&lt;br /&gt;&lt;br /&gt;//Create image background&lt;br /&gt;ImageFill($image,$width,$height,$white);&lt;br /&gt;//Draw background shape&lt;br /&gt;ImageRectangle($image, 0, 0, $width-1, $height-1, $black);&lt;br /&gt;//Output header&lt;br /&gt;ImageTTFText($image, 16, 0, $width/3 + 50, $y - 20, $black, $font, 'Poll Results');&lt;br /&gt;&lt;br /&gt;while ($row = mysql_fetch_object($result)) {&lt;br /&gt;  if ($total_votes &gt; 0)&lt;br /&gt;    $percent = intval(round(($row-&gt;num_votes/$total_votes)*100));&lt;br /&gt;  else&lt;br /&gt;    $percent = 0;&lt;br /&gt;&lt;br /&gt;//Output header for a particular value&lt;br /&gt;ImageTTFText($image,12,0,10, $y+($bar_height/2), $black, $font, $row-&gt;book_type);&lt;br /&gt;//Output percentage for a particular value&lt;br /&gt;ImageTTFText($image, 12, 0, 170, $y + ($bar_height/2),$red,$font,$percent.'%');&lt;br /&gt;&lt;br /&gt;$bar_length = $percent * $bar_unit;&lt;br /&gt;&lt;br /&gt;//Draw a shape that corresponds to 100%&lt;br /&gt;ImageRectangle($image, $bar_length+221, $y-2, (220+(100*$bar_unit)), $y+$bar_height, $black);&lt;br /&gt;//Output a bar for a particular value&lt;br /&gt;ImageFilledRectangle($image,220,$y-2,220+$bar_length, $y+$bar_height, $blue);&lt;br /&gt;//Output the number of votes&lt;br /&gt;ImageTTFText($image, 12, 0, 250+100*$bar_unit, $y+($bar_height/2), $black, $font, $row-&gt;num_votes.' votes cast.');&lt;br /&gt;&lt;br /&gt;//Going down to the next bar&lt;br /&gt;$y = $y + ($bar_height * 1.5);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//Tell the browser what kind of file is come in&lt;br /&gt;header("Content-Type: image/jpeg");&lt;br /&gt;&lt;br /&gt;//Output the newly created image in jpeg format&lt;br /&gt;ImageJpeg($image);&lt;br /&gt;&lt;br /&gt;//Free up resources&lt;br /&gt;ImageDestroy($image);&lt;br /&gt;?&gt; &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;Using dynamically generated images on the other pages&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;br /&gt;Since the header can be sent only once and it is the only way to tell the browser that you are going to send image, it is not so easy to insert automatically generated images to the regular pages. There are three ways to do it:&lt;br /&gt;&lt;br /&gt;    * The whole page can consist of the image.&lt;br /&gt;    * You can save image in the file and then refer to it using &lt;img&gt; HTML descriptor.&lt;br /&gt;    * You can  put a script producing image in HTML descriptor, e.g.:&lt;br /&gt;&lt;br /&gt;&lt;img height="120" alt="Dynamically generated image" src="generate_image.php" width="200" /&gt; &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-4541463851158755110?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/4541463851158755110/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=4541463851158755110' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/4541463851158755110'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/4541463851158755110'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/08/php-dynamic-image-generation.html' title='PHP: Dynamic Image Generation'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-5750621398082028196</id><published>2008-08-12T12:00:00.004-07:00</published><updated>2008-08-12T12:01:03.805-07:00</updated><title type='text'>Stored Procedures in MySQL</title><content type='html'>&lt;span style="font-family: arial;"&gt;The programmers and developers all over the world are celebrating the existence of MySQL 5.0 for a good reason. The version has finally paved the way for using stored procedures with this popular open source database. The stored procedures are hoarded at database server in the form of commands and SQL statements and could be invoked for any type of application. Thus, there is advantage for programmers to shed away the need of creating their own SQL; a tiresome job.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Without taking much of the time, let us understand the syntax for utilizing the procedures:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   1.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;       &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   2.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      CREATE ProcedureCREATE    [DEFINER = { user | CURRENT_USER }]PROCEDURE sp_name ([proc_parameter[,…]])&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   3.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;       &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   4.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      [characteristic …] routine_body&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   5.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;       &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   6.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      IN the above syntax, the parameters are specified AS IN, OUT OR INOUT. However, IN case of CREATE FUNCTION displayed below, the only parameter allowed IS IN.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   7.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;       &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   8.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      CREATE&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   9.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;       &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  10.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      [DEFINER = { user | CURRENT_USER }]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  11.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;       &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  12.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      FUNCTION sp_name ([func_parameter[,…]])&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  13.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;       &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  14.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      RETURNS type&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  15.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;       &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  16.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      [characteristic …] routine_body&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Return statement is included in the syntax for a function and it specifies the return type of the function. Routine body is included to define a valid SQL statement. The syntax contains characteristic to provide information regarding nature of data. This may include attributes like CONTAINS SQL, NO SQL, READS SQL DATA and MODIFIES SQL DATA.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Alter Procedure&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This statement is used to modify or alter the characteristics possessed by a stored procedure. Here is the syntax:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   1.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;       &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   2.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      ALTER {PROCEDURE | FUNCTION} sp_name [characteristic …]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;It offers you the advantage to bring in more than one change in the characteristics of stored procedures.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Drop Procedure&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;In order to remove a stored procedure, there is provision of DROP statement in MySQL database. The syntax for this takes the following shape:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   1.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;       &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   2.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      DROP {PROCEDURE | FUNCTION} [IF EXISTS] sp_name&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;IF EXISTS is used to check the existence of specified procedure or function. It saves the statement from generating an error in case the procedure or function doesn’t exist.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Other Statements For Procedures&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Apart from those mentioned above, there are other statements used for stored procedures. Here is the list o these statements:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    * Show Create Procedure – It is used to return the text of a stored procedure, which was defined previously using Create syntax. In the similar manner, there is Show Create Function statement to accomplish this task for stored function.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    * Show Procedure Status – It is used to return the characteristic of the specified stored procedure. These characteristics include name, type, creation date and so on. You may use Show Function Status also.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    * CALL – It is used to invoke the stored procedure created using Create Procedure statement.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    * Begin End – It is used to specify multiple statements for carrying out different types of operations and executions.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    * Declare – It is used to help programmers in declaring and defining local variables, conditions, procedures and so on.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    * SET – This statement is used to modify the values of local as well as global variables.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Also, there are condition statements like IF THEN ELSE, WHILE, CASE WHEN amongst others, which could be employed to operate these procedures.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Thus, MySQL stored procedures are tools for better performance, secure environment, providing ease of maintenance and also, for optimization.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-5750621398082028196?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/5750621398082028196/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=5750621398082028196' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/5750621398082028196'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/5750621398082028196'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/08/stored-procedures-in-mysql.html' title='Stored Procedures in MySQL'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-5654039220437561229</id><published>2008-08-12T12:00:00.003-07:00</published><updated>2008-08-12T12:00:45.690-07:00</updated><title type='text'>Recursive function in PHP</title><content type='html'>&lt;span style="font-family: arial;"&gt;recursive function is a function that calls itself repeatedly for a specified condition.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Here is an example function which calls iteself to perform a tree structure for a category table&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Here is the category table:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;category_id     parent_id     category_name&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;1     0     CMS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;2     0     Blogs&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;3     0     Forums&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;4     0     E-Commerce&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;5     1     Joomla&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;6     1     Mambo&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;7     6     Templates&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;8     6     Mods/Components&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;9     4     OSCommerce&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;10     2     Wordpress&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;11     10     Themes&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;12     10     Plugins&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   1.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      &lt;?php echo ‘&lt;select name="category"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   2.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      &lt;option value="’0‘"&gt;Root&lt;/option&gt;’;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   3.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      $allcats = getTree();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   4.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      foreach($allcats as $key=&gt;$value)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   5.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   6.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      echo "&lt;option value="’$key’"&gt;$value&lt;/option&gt;"&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   7.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   8.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      echo ‘&lt;/select&gt;’;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   9.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;       &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  10.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      function getTree($id=0)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  11.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  12.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      static $cates = array();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  13.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      static $times = 0;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  14.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      $times++;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  15.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      $result = mysql_query("SELECT category_id,category_name FROM category_table WHERE parent_id=$id ORDER BY category_name");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  16.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      while($row = mysql_fetch_assoc($result))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  17.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  18.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      $cates[$row[‘category_id’]] = str_repeat("|   ",$times-1)."|___".$row[‘category_name’];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  19.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      getTree($row[‘category_id’]);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  20.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  21.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      $times—;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  22.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      return $cates;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  23.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  24.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      ?&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The out put of this program would be the following select box:&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-5654039220437561229?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/5654039220437561229/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=5654039220437561229' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/5654039220437561229'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/5654039220437561229'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/08/recursive-function-in-php.html' title='Recursive function in PHP'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-6521656238995295132</id><published>2008-08-12T12:00:00.001-07:00</published><updated>2008-08-12T12:00:26.504-07:00</updated><title type='text'>PHP Interview Questions and Answers</title><content type='html'>&lt;span style="font-family: arial;"&gt;Question: Is PHP a case sensitive programming language?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Answer: PHP is a partially case sensitive programming language. We can use function names, class names in case insensitive manner.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Question: What is mean by LAMP?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Answer: LAMP means combination of Linux, Apache, MySQL and PHP.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Question: How do you get the user’s ip address in PHP?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Answer: Using the server variable: $_SERVER[’REMOTE_ADDR’]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Question: What is the difference between require and include?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Answer: When using require function to embed another file in php, it will give fatal error if the file is not exists.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        When using include function to embed another file in php, it will give warning if the file is not exists.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Question: How to find the number of elements in an array?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Answer: Using count($array) or sizeof($array).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Question: How do you make one way encryption for your passwords in PHP?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Answer: Using md5 function or sha1 function&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Question: How do you get ASCII value of a character?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Answer: By using ord function.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-6521656238995295132?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/6521656238995295132/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=6521656238995295132' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/6521656238995295132'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/6521656238995295132'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/08/php-interview-questions-and-answers.html' title='PHP Interview Questions and Answers'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-184433845551949431</id><published>2008-08-12T11:59:00.000-07:00</published><updated>2008-08-12T12:00:02.042-07:00</updated><title type='text'>Generating CAPTCHA Image Using PHP</title><content type='html'>&lt;span style="font-family: arial;"&gt;The CAPTCHA concept is very useful to prevent automated registration. If you have enabled gd library, you can create a captcha code for your registration form using PHP.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Consider the following parts of code, name the file as "captcha.php"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;session_start();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;if(isset($_SESSION[‘captcha’]))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;unset($_SESSION[‘captcha’]);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The above code will start session and clear the old captcha’s session value if it set.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;$num_chars = 5; //number of characters for captcha image&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;$characters = array_merge(range(0,9),range(‘A’,‘Z’),range(‘a’,‘z’)); //creating combination of numbers &amp;amp; alphabets&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;shuffle($characters); //shuffling the characters&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The above part of code describes the number of captcha characters and total available characters, here I am using all the lower and upper case alphabets and all numerics.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;//getting the required random 5 characters&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;$captcha_text = "";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;for($i=0;$i&lt;$num_chars;$i++)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;$captcha_text .= $characters[rand(0,count($characters)-1)];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;$_SESSION[‘captcha’] = $captcha_text; // assigning the text into session&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This part of code generated the required captcha code in a random manner from the available character array, also It assigns the value to session variable.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;header("Content-type: image/png"); // setting the content type as png&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;$captcha_image = imagecreatetruecolor(140, 30);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;$captcha_background = imagecolorallocate($captcha_image, 225, 238, 221); //setting captcha background colour&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;$captcha_text_colour = imagecolorallocate($captcha_image, 58, 94, 47); //setting cpatcha text colour&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;imagefilledrectangle($captcha_image, 0, 0, 140, 29, $captcha_background); //creating the rectangle&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;$font = ‘Arial.ttf’; //setting the font path&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;imagettftext($captcha_image, 20, 0, 11, 21, $captcha_text_colour, $font, $captcha_text);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;imagepng($captcha_image);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;imagedestroy($captcha_image);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The remaining code will draw the image.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;How to use this captcha?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;It’s simple, in your registration form put this part of code:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;img src="captcha.php" /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Then you can put a text box to enter the captcha value, and then you can compare the entered captcha value with the assigned captcha session value.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-184433845551949431?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/184433845551949431/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=184433845551949431' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/184433845551949431'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/184433845551949431'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/08/generating-captcha-image-using-php.html' title='Generating CAPTCHA Image Using PHP'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-2434950051109387857</id><published>2008-08-12T11:58:00.000-07:00</published><updated>2008-08-12T11:59:34.544-07:00</updated><title type='text'>File Uploading in PHP</title><content type='html'>&lt;span style="font-family: arial;"&gt;File uploading is very simple in PHP when comparing to other server side programming languages. File uploading is very useful in most of the situations like uploading user’s photos, uploading csv reports, uploading pdf reports and so on.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Making a simple front end with file browsing box:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   1.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;       &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   2.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      &lt;form method="post" enctype="multipart/form-data"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   3.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      Upload a file&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   4.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      &lt;input name="my_file" type="file"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   5.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      &lt;input value="Upload" type="submit"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   6.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      &lt;/form&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Note: You should have this enctype=”multipart/form-data”‘ in your form tag while uploading files.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The php source code to upload the files&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   1.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;       &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   2.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      if(isset($_FILES[‘my_file’][‘name’]) &amp;amp;&amp;amp; $_FILES[‘my_file’][‘name’] != ”)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   3.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   4.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      $upload_dir = ‘home/myaccount/public_html/images’;//uploading directory, this folder should have write permission to the current user&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   5.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      $upload_file = $upload_dir.‘/’.basename($_FILES[‘my_file’][‘name’]);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   6.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;       &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   7.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        //check if the file name already exists&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   8.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;         if(file_exists($upload_file))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   9.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;           {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  10.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;           echo "File Already Exists"; //if file already exists print the error message&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  11.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;           }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  12.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;           else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  13.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;           {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  14.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;                if(move_uploaded_file($_FILES[‘my_file’][‘tmp_name’],$upload_file))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  15.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;                   {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  16.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;                   echo "File Uploaded";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  17.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;                   }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  18.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;                  else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  19.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;                  {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  20.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;                  echo "There was a problem to upload file";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  21.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;                  }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  22.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;           }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  23.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  24.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      ?&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-2434950051109387857?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/2434950051109387857/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=2434950051109387857' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/2434950051109387857'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/2434950051109387857'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/08/file-uploading-in-php.html' title='File Uploading in PHP'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-8791405024006769178</id><published>2008-08-12T11:55:00.002-07:00</published><updated>2008-08-12T11:56:10.059-07:00</updated><title type='text'>Using session in PHP</title><content type='html'>&lt;span style="font-family: arial;"&gt;Keeping in mind the fact that Internet is a stateless platform and every request for a web page is treated as unique, there is a serious need of a tool to maintain the state. Otherwise, it will be a messy situation to keep track of requests made by a particular user. The good news is that use of PHP session serves the solution to this problem. This session variable is of great importance for web applications like shopping carts and is considered as equivalent to cookies, other significant way of maintaining the state.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;What Is PHP Session Capable Of&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;PHP session is capable of storing the information in the form of session variables, in order to handle the ever-increasing traffic on a website. For instance, consider a shopping website, with products scattered in different categories and different pages. In such a situation, a user may switch from one page t another and keep on adding products from different pages to his or her shopping cart.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Thus, in order to keep the track of a particular user on the shopping website, PHP sessions store user information and use it again and again. This is a powerful entity to serve the purpose for websites with huge customer base.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Getting Started With PHP Session&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;PHP session is initiated using following piece of code:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   1.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      session_start();?&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Now, suppose you visit a website in regular intervals in a specific period of time. The website must not treat you like a new user on every visit of yours. Rather, it must take the advantage of session variable to assign a user value to your first visit and use it again and again for every visit paid by you. Thus, we can add following code to accomplish this task:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   1.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      session_start();$_SESSION[‘counter’]++;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   2.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;       &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   3.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      echo "Welcome Back! You have viewed this page " . $_SESSION[‘counter’] . " times";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   4.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;       &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   5.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      ?&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Thus, if you revert to a particular website in short period of time, the counter will be incremented. If you visit the website 5th time, you might see it written somewhere that “Welcome Back! You have viewed this page 5 times”.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;How Does It Work&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Whenever you visit a web page, the PHP session sets information on your computer in the form of a cookie. It is generally a random key, formed by alphabets and numbers. In case, you visit another webpage of same website, the session explores the computer for a previously generated key. In case a match is found, that particular session is utilized. Otherwise, a new session is created with whole procedure related.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;How To End A PHP Session&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;A session is destroyed with the help of following code:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   1.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      session_destroy();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   2.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;       &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   3.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;      ?&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;It is a matter of fact that a session exists until and unless the associated user closes the browser used to open the website. Once the browser window is shut down, the session is destroyed. You may also decide the life of a session by bringing in following modifications in php.ini file.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;session.cookie_lifetime = 0&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;You may change the value from zero to number of seconds you want a session to live.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;You may also destroy a session variable using unset() or all session variable using session_unset().&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-8791405024006769178?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/8791405024006769178/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=8791405024006769178' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/8791405024006769178'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/8791405024006769178'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/08/using-session-in-php.html' title='Using session in PHP'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-688585813580439844</id><published>2008-08-12T11:55:00.001-07:00</published><updated>2008-08-12T11:55:48.500-07:00</updated><title type='text'>Email validation using PHP regular expression</title><content type='html'>&lt;span style="font-family: arial;"&gt;Regular expression is a wonderful concept, using this we can play with strings in PHP. The practical use of regular expression is:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    * Email validation&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    * validating domain name&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    * validating post code format etc.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;There are two types of regular expression functions:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   1. ereg functions or POSIX extended regular expression function, which is the standard functions for PHP&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;   2. preg functions or perl Compatible regular expressions&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;For this email validation program, we are going to use PHP’s standard regular expression function "ereg".&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Before entering the email validation program, its better to refer few basic syntax about regular expression functions.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;\s -&gt; this means an empty white space&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;^ -&gt; this means start of a string&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;$ -&gt; this means end of a string&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;. -&gt; this means any character&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;(cat|mat) -&gt; this means cat or mat&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;[0-9] -&gt; this means all numbers from 0 to 9 inclusive&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;[a-z] -&gt; this means all lowercase letters from a to z inclusive&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;[A-Z] -&gt; this means all uppercase letters from A to Z inclusive&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;[^a-z] -&gt; this means no occurrence of lowercase letters from a to z inclusive, the hat symbol (^) inside the sets denotes "not"&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;? -&gt; this means zero or one of the proceeding characters&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;* -&gt; this means zero or more characters&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;+ -&gt; this means one or more characters&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{3} -&gt; this means exactly three characters&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{3,} -&gt; this means three or more characters&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{3,6} -&gt; this means 3 to 6 characters, it may be 3 or 4 or 5 or 6&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Here is the php source code for email validation using php regx function:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;$email = "myemail@mydomain.com";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;if (ereg(‘^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$’,$email)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;echo ‘Valid email id’;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;} else {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;echo ‘Invalid email id’;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;?&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Now I am going to split the string pattern into 3 parts, ie&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;1] ^[a-zA-Z0-9._-]+@&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;2] [a-zA-Z0-9._-]+\.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;3] ([a-zA-Z]{2,4})$&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;1]^[a-zA-Z0-9._-]+@&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Here ^ symbol denotes that this is the start of the email part.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;a-zA-Z0-9._- denotes combination of characters to form the username section of an email&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;+ symbol denotes, it should have 1 or more characters from the proceeding sets&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;@ symbol is a default symbol between username and domain name parts.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;2] [a-zA-Z0-9._-]+\.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;a-zA-Z0-9._-  denotes combination of characters to form the domain name without the tld&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;+ symbol denotes, it should have 1 or more characters from the proceeding sets&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;\. symbol denotes, the dot operator proceeding to the tld, here we are using \ to escape&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;3] ([a-zA-Z]{2,4})$&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;a-zA-Z denotes the combination of chars to form the tld name&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{2,4} denotes the length of the tld may be between 2 to 4 characters&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;$ denotes the end of an email.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-688585813580439844?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/688585813580439844/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=688585813580439844' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/688585813580439844'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/688585813580439844'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/08/email-validation-using-php-regular.html' title='Email validation using PHP regular expression'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-8122363516726937995</id><published>2008-07-03T04:57:00.000-07:00</published><updated>2008-07-03T04:58:46.880-07:00</updated><title type='text'>Associative arrays in PHP</title><content type='html'>&lt;span style="font-family: arial;"&gt;A few days ago we studied about associative arrays in PHP. Now, you cannot sort an associative array by using the &lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;sort()&lt;/span&gt;&lt;span style="font-family: arial;"&gt; function. Let’s see what happens if you apply the &lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial;"&gt;sort()&lt;/span&gt;&lt;span style="font-family: arial;"&gt; function on an associative array in PHP:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;blockquote&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &lt;p&gt;&amp;lt;?php&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &lt;p&gt;$narray["IBM"]="International Business Machines";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $narray["MS"]="Microsoft";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $narray["CA"]="Computer Associated";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $narray["WHO"]="World Health Organization";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $narray["UK"]="United Kingdon";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $narray["BA"]="Something Random";&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &lt;p&gt;sort($narray);&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &lt;p&gt;foreach($narray as $key =&amp;gt; $value)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    &lt;img src="http://www.developertutorials.com/images/ck.gif" border="0" height="1" width="32" /&gt;print $key . " = " . $value . "&amp;lt;br /&amp;gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    }&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &lt;p&gt;?&amp;gt; &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;/blockquote&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;The outcome you get is:&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;0 = Computer Associated&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  1 = International Business Machines&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  2 = Microsoft&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  3 = Something Random&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  4 = United Kingdon&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  5 = World Health Organization&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;So you can see that if you apply the &lt;strong&gt;sort()&lt;/strong&gt; function on an associative array, it is sorted by the numeric value of the index. To sort an associative array, you use the &lt;strong&gt;asort()&lt;/strong&gt; function in the following manner:&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;blockquote&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &lt;p&gt;&amp;lt;?php&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &lt;p&gt;$narray["IBM"]="International Business Machines";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $narray["MS"]="Microsoft";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $narray["CA"]="Computer Associated";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $narray["WHO"]="World Health Organization";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $narray["UK"]="United Kingdon";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $narray["BA"]="Something Random";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    asort($narray);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    foreach($narray as $key =&amp;gt; $value)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    &lt;img src="http://www.developertutorials.com/images/ck.gif" border="0" height="1" width="32" /&gt;print $key . " = " . $value . "&amp;lt;br /&amp;gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    }&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &lt;p&gt;?&amp;gt; &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;/blockquote&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;The result is:&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;CA = Computer Associated&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  IBM = International Business Machines&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  MS = Microsoft&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  BA = Something Random&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  UK = United Kingdon&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  WHO = World Health Organization&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;As  you can see, the array has been sorted in the ascending order by the  value of the array, and not the string index value, or the key of the  array. You can use &lt;strong&gt;arsort()&lt;/strong&gt; to sort an associative array in the descending order.&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;To sort an associative array according to the key of the array, you can use the &lt;strong&gt;ksort()&lt;/strong&gt; function in the following manner:&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;blockquote&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &lt;p&gt;&amp;lt;?php&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &lt;p&gt;$narray["IBM"]="International Business Machines";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $narray["MS"]="Microsoft";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $narray["CA"]="Computer Associated";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $narray["WHO"]="World Health Organization";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $narray["UK"]="United Kingdon";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    $narray["BA"]="Something Random";&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &lt;p&gt;ksort($narray);&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &lt;p&gt;foreach($narray as $key =&amp;gt; $value)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    &lt;img src="http://www.developertutorials.com/images/ck.gif" border="0" height="1" width="32" /&gt;print $key . " = " . $value . "&amp;lt;br /&amp;gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    }&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &lt;p&gt;?&amp;gt; &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;/blockquote&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;Similarly, you can sort an associative array according to the key, in ascending order by using the &lt;strong&gt;krsort()&lt;/strong&gt; function.&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-8122363516726937995?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/8122363516726937995/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=8122363516726937995' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/8122363516726937995'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/8122363516726937995'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/07/associative-arrays-in-php.html' title='Associative arrays in PHP'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-8245232143694457280</id><published>2008-07-03T04:23:00.000-07:00</published><updated>2008-07-03T04:57:30.313-07:00</updated><title type='text'>Sorting an Array in PHP</title><content type='html'>&lt;p style="font-family: arial;"&gt;Now and then you need to sort your arrays alphabetically or numerically, if nothing else, then just to apply some programming logic and attain the desired output. You can sort an array in PHP by using two functions: &lt;strong&gt;sort()&lt;/strong&gt;, to sort an array in ascending order, and &lt;strong&gt;rsort()&lt;/strong&gt;, to sort an array in the reverse order, or descending order. I’ll illustrate this function with an example.&lt;/p&gt;&lt;p style="font-family: arial;"&gt;First, we loop through an array without applying any sorting:&lt;/p&gt;&lt;p style="font-family: arial;"&gt;&lt;blockquote&gt;&lt;br /&gt;  &lt;p&gt;&amp;lt;?php&lt;/p&gt;&lt;br /&gt;  &lt;p&gt;$narray[0]="Alfred";&lt;br /&gt;    $narray[1]="Robert";&lt;br /&gt;    $narray[2]="Deepak";&lt;br /&gt;    $narray[3]="Teresa";&lt;br /&gt;    $narray[4]="Joshua";&lt;br /&gt;    $narray[5]="Chandni";&lt;br /&gt;    $narray[6]="Sadiq";&lt;br /&gt;    $narray[7]="Vladimir";&lt;/p&gt;&lt;br /&gt;  &lt;p&gt;for($i=0; $i&amp;lt;8; $i++)&lt;br /&gt;    {&lt;br /&gt;    &lt;img src="http://www.developertutorials.com/images/ck.gif" border="0" height="1" width="32" /&gt;print $narray[$i] . "&amp;lt;br /&amp;gt;";&lt;br /&gt;    }&lt;/p&gt;&lt;br /&gt;  &lt;p&gt;?&amp;gt; &lt;/p&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;The output of this PHP code is:&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Alfred&lt;br /&gt;  Robert&lt;br /&gt;  Deepak&lt;br /&gt;  Teresa&lt;br /&gt;  Joshua&lt;br /&gt;  Chandni&lt;br /&gt;  Sadiq&lt;br /&gt;  Vladimir&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Now we apply the &lt;strong&gt;sort()&lt;/strong&gt; function and see what happens.&lt;/p&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;  &lt;p&gt;&amp;lt;?php&lt;/p&gt;&lt;br /&gt;  &lt;p&gt;$narray[0]="Alfred";&lt;br /&gt;    $narray[1]="Robert";&lt;br /&gt;    $narray[2]="Deepak";&lt;br /&gt;    $narray[3]="Teresa";&lt;br /&gt;    $narray[4]="Joshua";&lt;br /&gt;    $narray[5]="Chandni";&lt;br /&gt;    $narray[6]="Sadiq";&lt;br /&gt;    $narray[7]="Vladimir";&lt;/p&gt;&lt;br /&gt;  &lt;p&gt;sort($narray);&lt;/p&gt;&lt;br /&gt;  &lt;p&gt;for($i=0; $i&amp;lt;8; $i++)&lt;br /&gt;    {&lt;br /&gt;    &lt;img src="http://www.developertutorials.com/images/ck.gif" border="0" height="1" width="32" /&gt;print $narray[$i] . "&amp;lt;br /&amp;gt;";&lt;br /&gt;    }&lt;/p&gt;&lt;br /&gt;  &lt;p&gt;?&amp;gt; &lt;/p&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;The output of this PHP code is:&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Alfred&lt;br /&gt;  Chandni&lt;br /&gt;  Deepak&lt;br /&gt;  Joshua&lt;br /&gt;  Robert&lt;br /&gt;  Sadiq&lt;br /&gt;  Teresa&lt;br /&gt;  Vladimir&lt;/p&gt;&lt;br /&gt;&lt;p&gt;You  can see that the names have been alphabetically sorted in the ascending  order. To sort of the names in descending order, we change the program  like this:&lt;/p&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;  &lt;p&gt;&amp;lt;?php&lt;/p&gt;&lt;br /&gt;  &lt;p&gt;$narray[0]="Alfred";&lt;br /&gt;    $narray[1]="Robert";&lt;br /&gt;    $narray[2]="Deepak";&lt;br /&gt;    $narray[3]="Teresa";&lt;br /&gt;    $narray[4]="Joshua";&lt;br /&gt;    $narray[5]="Chandni";&lt;br /&gt;    $narray[6]="Sadiq";&lt;br /&gt;    $narray[7]="Vladimir";&lt;/p&gt;&lt;br /&gt;  &lt;p&gt;rsort($narray);&lt;/p&gt;&lt;br /&gt;  &lt;p&gt;for($i=0; $i&amp;lt;8; $i++)&lt;br /&gt;    {&lt;br /&gt;    &lt;img src="http://www.developertutorials.com/images/ck.gif" border="0" height="1" width="32" /&gt;print $narray[$i] . "&amp;lt;br /&amp;gt;";&lt;br /&gt;    }&lt;/p&gt;&lt;br /&gt;  &lt;p&gt;?&amp;gt; &lt;/p&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;Now the output is:&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Vladimir&lt;br /&gt;  Teresa&lt;br /&gt;  Sadiq&lt;br /&gt;  Robert&lt;br /&gt;  Joshua&lt;br /&gt;  Deepak&lt;br /&gt;  Chandni&lt;br /&gt;  Alfred&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-8245232143694457280?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/8245232143694457280/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=8245232143694457280' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/8245232143694457280'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/8245232143694457280'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/07/sorting-array-in-php.html' title='Sorting an Array in PHP'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-8527979882301082867</id><published>2008-06-25T23:52:00.000-07:00</published><updated>2008-06-25T23:56:27.571-07:00</updated><title type='text'>Developer Wallpapers</title><content type='html'>&lt;div style="text-align: center;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_QjAQxhBh3Q4/SGM8-LC18dI/AAAAAAAAAoA/Dn5GcnLZjrQ/s1600-h/php_1.jpg"&gt;&lt;img style="cursor: pointer;" src="http://bp2.blogger.com/_QjAQxhBh3Q4/SGM8-LC18dI/AAAAAAAAAoA/Dn5GcnLZjrQ/s400/php_1.jpg" alt="" id="BLOGGER_PHOTO_ID_5216079832239436242" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-8527979882301082867?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/8527979882301082867/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=8527979882301082867' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/8527979882301082867'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/8527979882301082867'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/06/developer-wallpapers.html' title='Developer Wallpapers'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp2.blogger.com/_QjAQxhBh3Q4/SGM8-LC18dI/AAAAAAAAAoA/Dn5GcnLZjrQ/s72-c/php_1.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-8400439504235331833</id><published>2008-06-25T23:35:00.000-07:00</published><updated>2008-06-25T23:45:50.038-07:00</updated><title type='text'>Desktop Wallpapers - PHP</title><content type='html'>&lt;div style="text-align: center;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp0.blogger.com/_QjAQxhBh3Q4/SGM5ODKjtjI/AAAAAAAAAnY/3EtLbuvUd0E/s1600-h/Crystal_Icon_Sets+copy.jpg"&gt;&lt;img style="cursor: pointer;" src="http://bp0.blogger.com/_QjAQxhBh3Q4/SGM5ODKjtjI/AAAAAAAAAnY/3EtLbuvUd0E/s400/Crystal_Icon_Sets+copy.jpg" alt="" id="BLOGGER_PHOTO_ID_5216075706955707954" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp0.blogger.com/_QjAQxhBh3Q4/SGM5OOw7kFI/AAAAAAAAAng/5r8-gw03lAE/s1600-h/PHP_wallpaper+copy.jpg"&gt;&lt;img style="cursor: pointer;" src="http://bp0.blogger.com/_QjAQxhBh3Q4/SGM5OOw7kFI/AAAAAAAAAng/5r8-gw03lAE/s400/PHP_wallpaper+copy.jpg" alt="" id="BLOGGER_PHOTO_ID_5216075710069444690" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp0.blogger.com/_QjAQxhBh3Q4/SGM5OJdv5BI/AAAAAAAAAno/x0_9K1c2Qss/s1600-h/phpwallpaper2.jpg"&gt;&lt;img style="cursor: pointer;" src="http://bp0.blogger.com/_QjAQxhBh3Q4/SGM5OJdv5BI/AAAAAAAAAno/x0_9K1c2Qss/s400/phpwallpaper2.jpg" alt="" id="BLOGGER_PHOTO_ID_5216075708646810642" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp0.blogger.com/_QjAQxhBh3Q4/SGM5OSO-DYI/AAAAAAAAAnw/wW3jhXddxA0/s1600-h/phpwallpaper3.jpg"&gt;&lt;img style="cursor: pointer;" src="http://bp0.blogger.com/_QjAQxhBh3Q4/SGM5OSO-DYI/AAAAAAAAAnw/wW3jhXddxA0/s400/phpwallpaper3.jpg" alt="" id="BLOGGER_PHOTO_ID_5216075711000743298" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp3.blogger.com/_QjAQxhBh3Q4/SGM5ObKh2sI/AAAAAAAAAn4/8Q15P5rmcyg/s1600-h/program.jpg"&gt;&lt;img style="cursor: pointer;" src="http://bp3.blogger.com/_QjAQxhBh3Q4/SGM5ObKh2sI/AAAAAAAAAn4/8Q15P5rmcyg/s400/program.jpg" alt="" id="BLOGGER_PHOTO_ID_5216075713398037186" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-8400439504235331833?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/8400439504235331833/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=8400439504235331833' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/8400439504235331833'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/8400439504235331833'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/06/desktop-wallpapers-php.html' title='Desktop Wallpapers - PHP'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp0.blogger.com/_QjAQxhBh3Q4/SGM5ODKjtjI/AAAAAAAAAnY/3EtLbuvUd0E/s72-c/Crystal_Icon_Sets+copy.jpg' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-3879639852599987566</id><published>2008-06-24T23:12:00.000-07:00</published><updated>2008-06-24T23:29:15.984-07:00</updated><title type='text'>The future of PHP 6</title><content type='html'>&amp;lt;div style=&amp;quot;text-align: center; font-weight: bold; font-family: arial;&amp;quot;&amp;gt;&lt;em&gt;Know what changes are in store for PHP V6 and how your scripts will change&lt;br /&gt;&lt;/em&gt;&amp;lt;div style=&amp;quot;text-align: left;&amp;quot;&amp;gt;&lt;em style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/em&gt;&lt;span style="font-weight: normal;"&gt;PHP's next edition, V6, includes new features and syntax improvements that will   make it easier to use from  an object-oriented standpoint. Other important features,   such as Unicode support in many of the  core functions, mean that PHP   V6 is positioned for better  international support and robustness.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p style="font-weight: normal;"&gt;PHP is already popular, used in millions of domains (according to Netcraft), supported   by most ISPs and used by household-name Web companies like Yahoo! The upcoming versions   of PHP aim  to add to this success by introducing new features that make PHP more usable   in some cases and more secure  in others. Are you ready for PHP V6? If you were   upgrading tomorrow, would your scripts execute just fine or would you have work to do?   This article focuses on the changes  for PHP V6 — some of them back-ported to   versions PHP V5.x — that could require some tweaks to your current scripts. &lt;/p&gt;             &lt;p style="font-weight: normal;"&gt;If you're not using PHP yet and have been thinking about it, take a look at its latest   features. These features, from Unicode  to core support for XML, make it even easier    for you to  write feature-filled PHP applications. &lt;/p&gt;             &lt;p style="font-weight: bold;"&gt;&lt;span style="font-size:130%;"&gt;&lt;a name="N1005D"&gt;&lt;span class="atitle"&gt;New PHP V6 features&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;              &lt;span style="font-weight: normal;"&gt;PHP V6 is currently available as a developer snapshot, so you can download and try out   many of the features and  changes listed in this article. For  features that   have been implemented in the  current snapshot&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;a name="N1006B"&gt;&lt;span class="smalltitle"&gt;&lt;span style="font-size:130%;"&gt;Improved Unicode suppor&lt;/span&gt;t&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;             &lt;p style="font-weight: normal;"&gt;Much improved for PHP V6 is support for Unicode strings in many of the core functions.   This new feature has  a big impact because it will allow PHP to support a broader set of   characters for international support. So, if you're a developer or architect using a   different language, such  as the Java™ programming language, because it has   better internationalization (i18n)  support than PHP, it'll be time to take another look at PHP when the support improves. &lt;/p&gt;              &lt;span style="font-weight: normal;"&gt;Because you can download and use a developer's version of PHP V6 today, you will see   some functions already supporting Unicode  strings. For a list of functions that have   been tested and verified  to handle Unicode&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="font-size:130%;"&gt;&lt;a name="N1008B"&gt;&lt;span class="smalltitle"&gt;Namespaces&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;             &lt;p style="font-weight: normal;"&gt;                 &lt;i&gt;Namespaces&lt;/i&gt; are a way of avoiding name collisions between functions and classes   without using prefixes in naming  conventions that make the names of your methods and   classes unreadable.  So by using namespaces, you can have class names that someone else   might use,  but now you don't have to worry about running into any problems. Listing 1   provides an example of a namespace  in PHP. &lt;/p&gt;             &lt;p style="font-weight: normal;"&gt;You won't have to update or change anything in your code because any PHP code you write   that doesn't include namespaces will run just fine. Because the namespaces feature   appears to be back-ported to V5.3 of PHP, when it becomes available, you can start to   introduce namespaces into  your own PHP applications.&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;a name="list1"&gt;&lt;b&gt;Example of a namespace&lt;/b&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;a name="list1"&gt;&lt;/a&gt;&lt;/b&gt;&lt;a name="list1"&gt;&lt;/a&gt;&lt;span style="font-weight: normal;"&gt;&lt;?php&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;pre class="displaycode"&gt;// I'm not sure why I would implement my own XMLWriter, but at least&lt;br /&gt;// the name of this one won't collide with the one built in to PHP&lt;br /&gt;namespace NathanAGood;&lt;br /&gt;class XMLWriter&lt;br /&gt;{&lt;br /&gt;   // Implementation here...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$writer = new NathanAGood::XMLWriter();&lt;br /&gt;&lt;br /&gt;?&gt;&lt;/pre&gt;&lt;p&gt;&lt;b&gt;&lt;a name="list1"&gt;&lt;/a&gt;&lt;/b&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-size:130%;"&gt;&lt;a name="N100A5"&gt;&lt;span class="atitle"&gt;Web 2.0 features&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;             &lt;p&gt;Depending on how you use PHP and what your scripts look like now, the language and   syntax differences  in PHP V6 may or may not affect you as much as the next features,   which are those that directly  allow you to introduce Web 2.0 features into your PHP application. &lt;/p&gt;             &lt;p&gt;&lt;span style="font-size:130%;"&gt;&lt;a name="N100AF"&gt;&lt;span class="smalltitle"&gt;SOAP&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;             &lt;p style="font-weight: normal;"&gt;SOAP is one of the protocols that Web services "speak" and is supported in quite a few   other languages, such as the  Java programming  language and Microsoft® .NET. Although there   are other ways to consume and expose Web  services, such as Representational State   Transfer (REST), SOAP  remains a common way of allowing different platforms to have   interoperability. In addition  to SOAP modules in the PHP Extension and Application   Repository (PEAR)  library, a SOAP extension to PHP was introduced in V5. This extension   wasn't enabled by default, so  you have to enable the extension or hope your ISP did. In   addition, PEAR packages  are available that allow you to build SOAP clients and servers, such as the SOAP package. &lt;/p&gt;             &lt;p style="font-weight: normal;"&gt;Unless you change the default, the SOAP extension will be enabled for you in V6. These   extensions provide an  easy way to implement SOAP clients and SOAP servers, allowing you   to build PHP applications that consume and provide Web services. &lt;/p&gt;             &lt;p&gt;If SOAP extensions are on by default, that means you won't have to configure them in   PHP. If you develop PHP  applications and publish them to an ISP, you may need to check   with your ISP to verify that  SOAP extensions will be enabled for you when they upgrade. &lt;/p&gt;             &lt;p&gt;&lt;span style="font-size:130%;"&gt;&lt;a name="N100C1"&gt;&lt;span class="smalltitle"&gt;XML&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;             &lt;p style="font-weight: normal;"&gt;As of PHP V5.1, XMLReader and XMLWriter have been part of the core of PHP, which makes   it easier for  you to work with XML in your PHP applications. Like the SOAP extensions,   this can be good news if you  use SOAP or XML because PHP V6 will be a better fit for   you than V4 out of the box. &lt;/p&gt;             &lt;p&gt;The XMLWriter and XMLReader are stream-based object-oriented classes that allow you to   read and write  XML without having to worry about the XML details.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-size:180%;"&gt;&lt;a name="N100CD"&gt;&lt;span class="atitle"&gt;Things removed&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;              &lt;p style="font-weight: normal;"&gt;In addition to having new features, PHP V6 will not have some other functions and   features that have been in previous  versions. Most of these things, such as &lt;code&gt;register_globals&lt;/code&gt; and  &lt;code&gt;safe_mode&lt;/code&gt;, are   widely considered "broken" in current PHP, as they may expose security risks. In an   effort to clean up PHP,  the functions and features listed in the next section will be   removed, or deprecated,  from PHP. Opponents of this removal will most likely cite   issues with existing scripts breaking  after ISPs or enterprises upgrade to PHP V6, but   proponents of this cleanup  effort will be happy that the PHP team is sewing up some   holes and providing a cleaner,  safer implementation. &lt;/p&gt;             &lt;p style="font-weight: normal;"&gt;Features that will be removed from the PHP version include:&lt;/p&gt;             &lt;ul&gt;&lt;li&gt;                     &lt;code&gt;magic_quotes&lt;/code&gt;                 &lt;/li&gt;&lt;li&gt;                     &lt;code&gt;register_globals&lt;/code&gt;                 &lt;/li&gt;&lt;li&gt;                     &lt;code&gt;register_long_arrays&lt;/code&gt;                 &lt;/li&gt;&lt;li&gt;                     &lt;code&gt;safe_mode&lt;/code&gt;                 &lt;/li&gt;&lt;/ul&gt;             &lt;p&gt;&lt;a name="N10101"&gt;&lt;span class="smalltitle"&gt;                 &lt;code&gt;magic_quotes&lt;/code&gt;             &lt;/span&gt;&lt;/a&gt;&lt;/p&gt;              &lt;p style="font-weight: normal;"&gt;Citing portability, performance, and inconvenience, the PHP documentation discourages   the use of  &lt;code&gt;magic_quotes&lt;/code&gt;. It's so discouraged that it's being   removed from PHP V6 altogether, so before upgrading to PHP V6, make sure that all your   code avoids using  &lt;code&gt;magic_quotes&lt;/code&gt;. If you're using   &lt;code&gt;magic_quotes&lt;/code&gt;  to escape strings for database calls, use your   database  implementation's parameterized queries, if they're supported. If not, use your   database implementation's  escape function, such as &lt;code&gt;mysql_escape_string&lt;/code&gt; for MySQL or  &lt;code&gt;pg_escape_string&lt;/code&gt; for  PostgreSQL. Listing 2 shows an example of &lt;code&gt;magic_quotes&lt;/code&gt; use. &lt;/p&gt;&lt;p style="font-weight: normal;"&gt; &lt;/p&gt;&lt;b&gt;&lt;a name="list2"&gt;&lt;b&gt; Using &lt;code&gt;magic_quotes&lt;/code&gt; (discouraged)&lt;br /&gt;&lt;br /&gt;&lt;/b&gt;&lt;/a&gt;&lt;/b&gt;&lt;pre class="displaycode"&gt;&lt;?php&lt;br /&gt;// Assuming magic_quotes is on...&lt;br /&gt;$sql = "INSERT INTO USERS (USERNAME) VALUES $_GET['username']";&lt;br /&gt;?&gt;&lt;/pre&gt;&lt;a name="list2"&gt;&lt;br /&gt;&lt;span style="font-weight: normal;"&gt;After preparing your PHP code for the new versions of PHP, your code should look like that in Listing 3.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;b&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;a name="list3"&gt;&lt;b&gt;Listing 3. Using parameterized queries (recommended)&lt;br /&gt;&lt;/b&gt;&lt;/a&gt;&lt;/b&gt;&lt;pre class="displaycode"&gt;&lt;?php&lt;br /&gt;// Using the proper parameterized query method for MySQL, as an example&lt;br /&gt;$statement = $dbh-&gt;prepare("INSERT INTO USERS (USERNAME) VALUES ?");&lt;br /&gt;$statement-&gt;execute(array($_GET['username']));&lt;br /&gt;?&gt;&lt;/pre&gt;&lt;a name="list2"&gt;&lt;/a&gt;&lt;a name="list3"&gt;&lt;br /&gt;&lt;/a&gt;&lt;b&gt;&lt;a name="list3"&gt;&lt;/a&gt;&lt;/b&gt;&lt;b&gt;&lt;a name="list2"&gt;&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;em&gt;&lt;/em&gt;&lt;br /&gt;&lt;p style="font-weight: normal;"&gt;Now that support for &lt;code&gt;magic_quotes&lt;/code&gt; will be completely   removed, the &lt;code&gt;get_magic_quotes_gpc()&lt;/code&gt;  function will no longer   be available. This may affect some  of the older PHP scripts, so before updating, make   sure you fix any locations in which  this functions exists. &lt;/p&gt;             &lt;p style="font-weight: normal;"&gt;&lt;a name="N1014C"&gt;&lt;span class="smalltitle"&gt;                 &lt;code&gt;register_globals&lt;/code&gt;             &lt;/span&gt;&lt;/a&gt;&lt;/p&gt;             &lt;p&gt;&lt;span style="font-weight: normal;"&gt;The &lt;/span&gt;&lt;code style="font-weight: normal;"&gt;register_globals&lt;/code&gt;&lt;span style="font-weight: normal;"&gt; configuration key was already defaulted   to off in PHP V4.2, which was controversial at the time. When &lt;/span&gt;&lt;code style="font-weight: normal;"&gt;register_globals&lt;/code&gt;&lt;span style="font-weight: normal;"&gt; is turned on,  it was easy to use variables that   could be injected with values from HTML forms.  These variables don't really require   initialization in your scripts, so  it's easy to write scripts with gaping security   holes. The &lt;/span&gt;&lt;code style="font-weight: normal;"&gt;register_globals&lt;/code&gt;&lt;span style="font-weight: normal;"&gt; documentation &lt;/span&gt;&lt;span style="font-weight: normal;"&gt;provides much more  information about &lt;/span&gt;&lt;code style="font-weight: normal;"&gt;register_globals&lt;/code&gt;&lt;span style="font-weight: normal;"&gt;. See  Listing 4 for an example of using &lt;/span&gt;&lt;code style="font-weight: normal;"&gt;register_globals&lt;/code&gt;.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;a name="list4"&gt;&lt;b&gt;Using &lt;code&gt;register_globals&lt;/code&gt; (discouraged)&lt;/b&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;a name="list4"&gt;&lt;/a&gt;&lt;/b&gt;&lt;a name="list4"&gt;&lt;br /&gt;&lt;/a&gt;&lt;/p&gt;&lt;pre class="displaycode"&gt;&lt;?php&lt;br /&gt;// A security hole, because if register_globals is on, the value for user_authorized&lt;br /&gt;// can be set by a user sending them on the query string&lt;br /&gt;// (i.e., http://www.example.com/myscript.php?user_authorized=true)&lt;br /&gt;if ($user_authorized) {&lt;br /&gt;   // Show them everyone's sensitive data...&lt;br /&gt;}&lt;br /&gt;?&gt;&lt;/pre&gt;&lt;p&gt;&lt;b&gt;&lt;a name="list4"&gt;&lt;/a&gt;&lt;/b&gt; &lt;/p&gt;&lt;br /&gt;&lt;span style="font-weight: normal;"&gt;If your PHP code uses global variables, you should update it. If you don't update your   code to get prepared for newer versions  of PHP, consider updating it for security   reasons. When you're finished,  your code should look like Listing 5.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;b&gt;&lt;a name="list5"&gt;&lt;b&gt;Listing 5. Being specific instead (recommended)&lt;br /&gt;&lt;/b&gt;&lt;/a&gt;&lt;/b&gt;&lt;pre class="displaycode"&gt;&lt;?php&lt;br /&gt;function is_authorized() {&lt;br /&gt;   if (isset($_SESSION['user'])) {&lt;br /&gt;       return true;&lt;br /&gt;   } else {&lt;br /&gt;       return false;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$user_authorized = is_authorized();&lt;br /&gt;?&gt;&lt;/pre&gt;&lt;a name="list5"&gt;&lt;br /&gt;&lt;/a&gt;&lt;p&gt;&lt;span style="font-size:130%;"&gt;&lt;a name="N1018C"&gt;&lt;span class="smalltitle"&gt;register_long_arrays&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;             &lt;p&gt;&lt;span style="font-weight: normal;"&gt;The &lt;/span&gt;&lt;code style="font-weight: normal;"&gt;register_long_arrays&lt;/code&gt;&lt;span style="font-weight: normal;"&gt; setting, when turned on, registers   the &lt;/span&gt;&lt;code style="font-weight: normal;"&gt;$HTTP_*_VARS&lt;/code&gt;&lt;span style="font-weight: normal;"&gt;  predefined variables. If you're using the   longer variables, update now to  use the shorter variables. This setting was introduced   in PHP V5 — presumably for backward-compatibility — and the PHP folks   recommend turning it off for performance reasons. Listing 6 shows an example of &lt;/span&gt;&lt;code style="font-weight: normal;"&gt;register_long-arrays&lt;/code&gt; use.&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;a name="list6"&gt;&lt;b&gt;Using deprecated registered arrays (discouraged)&lt;/b&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;a name="list6"&gt;&lt;/a&gt;&lt;/b&gt;&lt;a name="list6"&gt;&lt;br /&gt;&lt;/a&gt;&lt;/p&gt;&lt;pre class="displaycode"&gt;&lt;?php&lt;br /&gt;   // Echo's the name of the user value given on the query string, like&lt;br /&gt;   // http://www.example.com/myscript.php?username=ngood&lt;br /&gt;   echo "Welcome, $HTTP_GET_VARS['username']!";&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;If your PHP code looks like that shown in Listing 6, update it to look like that in&lt;br /&gt; Listing 7. Shut off the  &lt;code&gt;register_long_arrays&lt;/code&gt; setting if&lt;br /&gt; it's on and  test your scripts again.&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;&lt;b&gt;&lt;a name="list6"&gt;&lt;b&gt; &lt;/b&gt;&lt;/a&gt;&lt;/b&gt; &lt;/p&gt;&lt;b&gt;&lt;a name="list5"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/b&gt;&lt;b&gt;&lt;a name="list7"&gt;&lt;b&gt;Using &lt;code&gt;$_GET&lt;/code&gt; (recommended)&lt;br /&gt;&lt;/b&gt;&lt;/a&gt;&lt;/b&gt;&lt;pre class="displaycode"&gt;&lt;?php&lt;br /&gt;   // Using the supported $_GET array instead.&lt;br /&gt;   echo "Welcome, $_GET['username']!";&lt;br /&gt;?&gt;&lt;/pre&gt;&lt;a name="list7"&gt;&lt;/a&gt;&lt;span style="font-weight: bold;font-size:180%;" &gt;&lt;code&gt;safe_mode&lt;/code&gt;&lt;/span&gt;&lt;p&gt;&lt;a name="N101C4"&gt;&lt;span class="smalltitle"&gt;             &lt;/span&gt;&lt;/a&gt;&lt;/p&gt;             &lt;p&gt;&lt;span style="font-weight: normal;"&gt;The &lt;/span&gt;&lt;code style="font-weight: normal;"&gt;safe_mode&lt;/code&gt;&lt;span style="font-weight: normal;"&gt; configuration key, when turned on, ensures   that the owner of a  file being operated on matches the owner of the script that is   executing. It was originally  a way to attempt to handle security when operating in a   shared server environment,  like many ISPs would have. (For a link to a list of the   functions affected by  this &lt;/span&gt;&lt;code style="font-weight: normal;"&gt;safe_mode&lt;/code&gt;&lt;span style="font-weight: normal;"&gt; change,&lt;/span&gt; Your PHP  code will be unaffected by this change, but   it's good to be  aware of it in case you're setting up PHP in the future or counting on   &lt;code style="font-weight: normal;"&gt;safe_mode&lt;/code&gt; in your  scripts. &lt;/p&gt;             &lt;p&gt;&lt;span style="font-size:130%;"&gt;&lt;a name="N101E1"&gt;&lt;span class="smalltitle"&gt;PHP tags&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;              &lt;p&gt;&lt;span style="font-weight: normal;"&gt;Microsoft Active Server Pages (ASP)-style tags — the shorter version of the PHP   tags — are no longer  supported. To make sure this is not an issue for your   scripts, verify that you aren't  using the &lt;/span&gt;&lt;code style="font-weight: normal;"&gt;&lt;%&lt;/code&gt;&lt;span style="font-weight: normal;"&gt; or &lt;/span&gt;&lt;code style="font-weight: normal;"&gt;%&gt;&lt;/code&gt;&lt;span style="font-weight: normal;"&gt; tags in your  PHP files. Replace them with &lt;/span&gt;&lt;code style="font-weight: normal;"&gt;&lt;?php&lt;/code&gt;&lt;span style="font-weight: normal;"&gt; and  &lt;/span&gt;&lt;code style="font-weight: normal;"&gt;?&gt;&lt;/code&gt;. &lt;/p&gt;             &lt;p&gt;&lt;span style="font-size:130%;"&gt;&lt;a name="N101FF"&gt;&lt;span class="smalltitle"&gt;FreeType 1 and GD 1&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;              &lt;p style="font-weight: normal;"&gt;The PHP team is removing support for both FreeType 1 and GD 1, citing the age and lack   of ongoing developments of  both libraries as the reason. Newer versions of both of   these libraries are available that provide better  functionality. For more information   about FreeType and  GD &lt;/p&gt;             &lt;p style="font-weight: normal;"&gt;&lt;a name="N1020D"&gt;&lt;span class="smalltitle"&gt;                 &lt;code&gt;ereg&lt;/code&gt;             &lt;/span&gt;&lt;/a&gt;&lt;/p&gt;             &lt;p&gt;&lt;span style="font-weight: normal;"&gt;The &lt;/span&gt;&lt;code style="font-weight: normal;"&gt;ereg&lt;/code&gt;&lt;span style="font-weight: normal;"&gt; extension, which supports Portable Operating System   Interface (POSIX) regular expressions, is being removed from core PHP support. If you   are using any of the POSIX  regex functions, this change will affect you unless you   include the &lt;/span&gt;&lt;code style="font-weight: normal;"&gt;ereg&lt;/code&gt;&lt;span style="font-weight: normal;"&gt; functionality. If you're using POSIX regex   today, consider taking the  time to update your regex functions to use the   Perl-Compatible Regular Expression  (PCRE) functions because they give you more features   and perform better. Table  1 provides a list of the POSIX regex functions that will not be available after   &lt;/span&gt;&lt;code style="font-weight: normal;"&gt;ereg&lt;/code&gt; is removed. Their PCRE replacements are also shown. &lt;/p&gt;&lt;a name="list7"&gt;&lt;br /&gt;&lt;/a&gt;&lt;b&gt;&lt;a name="list7"&gt;&lt;/a&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-3879639852599987566?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/3879639852599987566/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=3879639852599987566' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/3879639852599987566'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/3879639852599987566'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/06/future-of-php-6.html' title='The future of PHP 6'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-8531321953465755904</id><published>2008-06-24T22:39:00.000-07:00</published><updated>2008-06-24T22:41:18.310-07:00</updated><title type='text'>Installing PHP6 (For beginners)</title><content type='html'>&lt;p style="font-family: arial;"&gt;Installing PHP6 (For beginners)&lt;br /&gt;&lt;br /&gt;Hello all, you might have read that PHP6 is under and has been under development for the past few months. Well after hacking around some code trying to get some DirectoryIterator unicoded and ready for php6, I have ran into the problem of compiling php6.. So I figured, might as well give an idea to anyone who feels like on how to install (compile) php6.&lt;/p&gt;&lt;p style="font-family: arial;"&gt;Notice that I will be using the command:&lt;/p&gt;&lt;ul style="font-family: arial;"&gt;&lt;li&gt; su -c "command" &lt;/li&gt;&lt;/ul&gt;&lt;p style="font-family: arial;"&gt;Which is because some system do not have sudoers setup yet (yes it does still exist) &lt;/p&gt;&lt;p style="font-family: arial;"&gt;Ok, before reading this, here's a couple usefull links:&lt;br /&gt;&lt;br /&gt;&lt;a title="PHP's site" href="http://php.net/"&gt;http://php.net/&lt;/a&gt;&lt;br /&gt;&lt;a title="Anonymous CVS with PHP" href="http://php.net/anoncvs.php"&gt;http://php.net/anoncvs.php&lt;/a&gt;  (Most used here)&lt;br /&gt;&lt;a title="Daily Snaps" href="http://snaps.php.net/"&gt;http://snaps.php.net/&lt;/a&gt;&lt;br /&gt;&lt;a title="CVS PHP WebView" href="http://cvs.php.net/"&gt;http://cvs.php.net/&lt;/a&gt;&lt;br /&gt;&lt;a title="Flex 2.5.4 download" href="http://site.n.ml.org/info/flex/"&gt;http://site.n.ml.org/info/flex/&lt;/a&gt;&lt;br /&gt;&lt;a title="ICU's page" href="http://icu.sourceforge.net/download/3.6.html"&gt;http://icu.sourceforge.net/download/3.6.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Hello all, you might have read that PHP6 is under and has been under development for the past few months. Well after hacking around some code trying to get some DirectoryIterator unicoded and ready for php6, I have ran into the problem of compiling php6.. So I figured, might as well give an idea to anyone who feels like on how to install (compile) php6.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;There is also a numerous amount of tools you'll have to install before you might become able to try to compile PHP6.&lt;/p&gt;&lt;ul style="font-family: arial;"&gt;&lt;li&gt;autoconf: 2.13&lt;/li&gt;&lt;li&gt;automake: 1.4+&lt;/li&gt;&lt;li&gt;libtool: 1.4.x+ (except 1.4.2)&lt;/li&gt;&lt;li&gt;bison: 1.28, 1.35, 1.75, 2.0 or higher&lt;/li&gt;&lt;li&gt;flex: 2.5.4&lt;/li&gt;&lt;li&gt;re2c: 0.9.11+&lt;/li&gt;&lt;/ul&gt;&lt;p style="font-family: arial;"&gt;&lt;br /&gt;Of course, all this information can be found on the &lt;a title="PHP's page" href="http://php.net/"&gt;php's page&lt;/a&gt;  (&lt;a title="Anonymous CVS Php" href="http://php.net/anoncvs.php"&gt;http://php.net/anoncvs.php&lt;/a&gt; )&lt;br /&gt;&lt;br /&gt;Also, the coolest part of this (The heart of php6 imho - else than andrei and sara (joking))) is that package you'll have to install:&lt;br /&gt;&lt;a title="ICU's page" href="http://icu.sourceforge.net/download/3.6.html"&gt;http://icu.sourceforge.net/download/3.6.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;You can start by executing the following commans:&lt;/p&gt;&lt;ul style="font-family: arial;"&gt;&lt;li&gt; mkdir ~/development; cd ~/development&lt;/li&gt;&lt;li&gt;wget ftp://ftp.software.ibm.com/software/globalization/icu/3.6/icu4c-3_6-src.tgz&lt;/li&gt;&lt;/ul&gt;&lt;p style="font-family: arial;"&gt;   + ^ This is for linux of course&lt;/p&gt;&lt;ul style="font-family: arial;"&gt;&lt;li&gt; tar -xzvf icu4c-3_6-src.tgz&lt;/li&gt;&lt;li&gt;cd icu; cd source&lt;/li&gt;&lt;li&gt; su -c "mkdir /usr/local/icu"&lt;/li&gt;&lt;li&gt; ./configure --prefix=/usr/local/icu &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make install&lt;/li&gt;&lt;/ul&gt;&lt;p style="font-family: arial;"&gt;   ^ You might get an error related to zlib (Version to low, I strongly suggest to update it if&lt;br /&gt;    you get the error)&lt;br /&gt;&lt;br /&gt;So what? You are done with ICU compiling ? Let's move on shall we ?&lt;br /&gt;&lt;br /&gt;So before installing php6, you have to download it. You can choose from various places, first&lt;br /&gt;you can simply look at http://snaps.php.net (Which are frequent snapshots of the cvs repository) and get the latest php6 snap or you can simply make an anonymous checkout (for those who dont' have a username here's how to do that)&lt;br /&gt;&lt;br /&gt;It is also recommended that you put these configurations into your ~/.cvsrc file:&lt;/p&gt;&lt;ul style="font-family: arial;"&gt;&lt;li&gt; cvs -z3&lt;/li&gt;&lt;li&gt; update -d -P&lt;/li&gt;&lt;li&gt; checkout -P&lt;/li&gt;&lt;li&gt; diff -u&lt;/li&gt;&lt;/ul&gt;&lt;p style="font-family: arial;"&gt;&lt;br /&gt;Then you are ready to go for your anonymous cvs checkout &lt;/p&gt;&lt;p style="font-family: arial;"&gt;(Username: "&lt;strong&gt;cvsread&lt;/strong&gt;" and password "&lt;strong&gt;phpfi&lt;/strong&gt;")&lt;/p&gt;&lt;ul style="font-family: arial;"&gt;&lt;li&gt;cvs -d :pserver:cvsread@cvs.php.net:/repository login&lt;/li&gt;&lt;li&gt;cvs -d :pserver:cvsread@cvs.php.net:/repository checkout php6  &lt;/li&gt;&lt;/ul&gt;&lt;p style="font-family: arial;"&gt;&lt;br /&gt;The previous commands will execute a cvs checkout (Get the code) and store it into ~/development/php6&lt;br /&gt;&lt;br /&gt;Once you have installed all the tools stated above, did your checkout, and all is square here comes the second part.&lt;br /&gt;&lt;br /&gt;You'll have to execute the following commands (Using apache2 for this example):&lt;/p&gt;&lt;ol style="font-family: arial;"&gt;&lt;li&gt;  cd php6&lt;/li&gt;&lt;li&gt; ./buildconf&lt;/li&gt;&lt;li&gt; sudo "mkdir /usr/local/php6"&lt;/li&gt;&lt;li&gt; ./configure --prefix=/usr/local/php6 --with-icu-dir=/usr/local/icu --with-apxs2=/usr/bin/apxs2&lt;/li&gt;&lt;/ol&gt;&lt;p style="font-family: arial;"&gt;   (Just using apxs2 as an example)&lt;br /&gt;  ^ You can of course add more options as such as --with-mysql=/usr/bin (if mysql is in bin)&lt;br /&gt;    --with-phar --with-bz2. Just see the command "./configure --help" for a list of options.&lt;br /&gt;&lt;br /&gt;  ^ Also, if the make is dying because of some flex problems, you can use the command&lt;br /&gt;    "apt-get install flex-old" or simply get the source at: &lt;a title="flex 2.5.4" href="http://site.n.ml.org/download/20030401085856/flex/flex-2.5.4a.tar.gz"&gt;http://site.n.ml.org/download/20030401085856/flex/flex-2.5.4a.tar.gz&lt;/a&gt; &lt;/p&gt;&lt;ol style="font-family: arial;"&gt;&lt;li&gt; then ,if it all went well of course, you type:&lt;/li&gt;&lt;li&gt; make &amp;amp;&amp;amp; su -c "make install"&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If it all went well, then you should have the php6 files all ready to be used in /usr/local/php6 &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Just give a look at it to see if you have new directories, etc.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If you used the --with-apxs(2) options, you should already be set with the apache load_modules et all. You might notice that it said LoadModule php5 well don't worry that's all good you'll just need your libphp6.so which is usually well placed when using --with-apxs.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If you are not sure, just look at your /etc/apache2/httpd.conf and /etc/apache2/mods-enabled/php5.load files to see if you have it pointing to libphp6.so (Which it probably is)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;So are you ready ? Last command line command:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt; - su -c "apache2ctl restart"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If you do not get an error, you should be able to go to your web directory &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;(Here I am using /var/www on my development box) and add a file with this content:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;color:#cc33cc;" &gt;&lt;?php&lt;/span&gt;&lt;br /&gt;    &lt;span style="font-family: arial;color:#669966;" &gt;phpinfo&lt;/span&gt;&lt;span style="font-family: arial;"&gt;();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;color:#cc33cc;" &gt;?&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If you are lucky and it all went well, then you will see "PHP Version 6.0.0-dev" with probably a million warnings. Well it is installed, you can start fiddling around and testing.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Hope this helps a couple people (Even though a lot of you probably gave me hints during this crusade)&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-8531321953465755904?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/8531321953465755904/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=8531321953465755904' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/8531321953465755904'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/8531321953465755904'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/06/installing-php6-for-beginners.html' title='Installing PHP6 (For beginners)'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-4374737088921010702</id><published>2008-06-24T02:58:00.000-07:00</published><updated>2008-06-24T03:02:22.954-07:00</updated><title type='text'>PHP Paging Code: Break up records into pages</title><content type='html'>&lt;span style="font-family: arial;"&gt;&lt;p&gt;&amp;lt;!-- &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  ============= Connection.php =================&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  //--&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  $server = &amp;quot;localhost&amp;quot;; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  $user = &amp;quot;root&amp;quot;; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  $pass = &amp;quot;&amp;quot;; &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;$OpSe = mysql_connect($server, $user, $pass ) or die(mysql_error()):&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  $OpDb = mysql_select_db(&amp;quot;DATABASE_NAME&amp;quot;,$OpSe) or die(mysql_error());&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  ?&amp;gt;&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt; &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt; &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt; &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;&amp;lt;!-- &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  ============= Paging.php =================&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  //--&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;style type=&amp;quot;text/css&amp;quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  a.spage:link{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  border: 1px solid #000000;font-family:verdana; font-size:10px;padding-top:1px; padding-bottom:2px;padding-left:4px;padding-right:4px;color:white;font-weight:bold;text-decoration:none;background-color:#ffffff; color:#000000;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  }&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;p&gt;a.lspage:link{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  border: 1px solid #000000;font-family:verdana; font-size:10px;padding-top:1px; padding-bottom:2px;padding-left:4px;padding-right:4px;color:white;font-weight:bold;text-decoration:none; color:#000000;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;/style&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  // set record display per page....&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  $PP = 10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  //---------------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  isset($_GET[&amp;quot;st&amp;quot;]) &amp;amp;&amp;amp; $_GET[&amp;quot;st&amp;quot;]!=&amp;quot;&amp;quot; ? $st=$_GET[&amp;quot;st&amp;quot;] : $st=0;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  ?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;table border=&amp;quot;1&amp;quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;tr bgcolor=&amp;quot;#999999&amp;quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Field1 Date&amp;lt;/b&amp;gt;&amp;lt;/td&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Field2 Date&amp;lt;/b&amp;gt;&amp;lt;/td&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Field3 Date&amp;lt;/b&amp;gt;&amp;lt;/td&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Field4 Date&amp;lt;/b&amp;gt;&amp;lt;/td&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;/tr&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  $query =&amp;quot;SELECT field1, field2, field3, field4 FROM TABLE_NAME LIMIT &amp;quot;.$st.&amp;quot;,&amp;quot;.$PP;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  $rs = mysql_query($query) or die(mysql_error()); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  while($row = mysql_fetch_array($rs)){&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  ?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;tr bgcolor=&amp;quot;#CCCCCC&amp;quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;td&amp;gt;&amp;lt;?=$row[&amp;quot;field1&amp;quot;]?&amp;gt;&amp;lt;/td&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;td&amp;gt;&amp;lt;?=$row[&amp;quot;field2&amp;quot;]?&amp;gt;&amp;lt;/td&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;td&amp;gt;&amp;lt;?=$row[&amp;quot;field3&amp;quot;]?&amp;gt;&amp;lt;/td&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;td&amp;gt;&amp;lt;?=$row[&amp;quot;field4&amp;quot;]?&amp;gt;&amp;lt;/td&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;/tr&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  ?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;/table&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;table border=&amp;quot;0&amp;quot; cellpadding=&amp;quot;0&amp;quot; cellspacing=&amp;quot;0&amp;quot; width=&amp;quot;99%&amp;quot; align=&amp;quot;center&amp;quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;tr&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;td width=&amp;quot;1%&amp;quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;? if($st&amp;gt;=$PP){?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;a href=&amp;quot;?st=&amp;lt;?=$st-$PP?&amp;gt;&amp;quot;&amp;gt;Pre&amp;lt;/a&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;? }?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;/td&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;? &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  // Do not change below this line----------------------------------------- &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  $total--; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  $pgv = $total/$PP;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  if($pgv&amp;gt;1)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  $pg_a = explode(&amp;quot;.&amp;quot;,$pgv); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  $pg_a = $pgv; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  if($pg_a[1]&amp;gt;0)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  $pg = $pg_a[0]+1; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  $pg = 0;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  if($pg==&amp;quot;&amp;quot;)$pg = $pgv;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  $selpage = $st / $PP;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  $selpage++;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  $selpage = (int) $selpage; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  for($ploop=1,$stl=1    ;$ploop&amp;lt;=$pg;$ploop++,$stl+=$PP){&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  echo ' &amp;lt;a href=&amp;quot;?st='.$stl.'&amp;quot; class=&amp;quot;';&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  echo $ploop==$selpage ? &amp;quot;spage&amp;quot; : &amp;quot;lspage&amp;quot;;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  echo '&amp;quot;&amp;gt;'.$ploop.'&amp;lt;/a&amp;gt; ';&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  // Do not change above this line-----------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  ?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;/td&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;td align=&amp;quot;right&amp;quot; width=&amp;quot;1%&amp;quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;? if($st&amp;lt;$total-$PP){?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;a href=&amp;quot;?st=&amp;lt;?=$st+$PP?&amp;gt;&amp;quot;&amp;gt;Next&amp;lt;/a&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;? }?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;/td&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;/tr&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &amp;lt;/table&amp;gt; &lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-4374737088921010702?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/4374737088921010702/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=4374737088921010702' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/4374737088921010702'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/4374737088921010702'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/06/php-paging-code-break-up-records-into.html' title='PHP Paging Code: Break up records into pages'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-4163406538214414328</id><published>2008-06-21T09:54:00.000-07:00</published><updated>2008-06-21T09:57:53.937-07:00</updated><title type='text'>Advertisement</title><content type='html'>&lt;center&gt;&lt;br /&gt;&lt;iframe src="http://www.karachicorner.com/domains/banners/randomurl.php" marginheight="0" marginwidth="0" frameborder="0" height="40" width="340"&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;iframe src="http://www.karachicorner.com/domains/banners/randombanner.php" marginheight="0" marginwidth="0" frameborder="0" height="60" width="380"&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;/center&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-4163406538214414328?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/4163406538214414328/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=4163406538214414328' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/4163406538214414328'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/4163406538214414328'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/06/advertisement.html' title='Advertisement'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-8288888992689333026</id><published>2008-06-18T02:40:00.000-07:00</published><updated>2008-06-18T02:53:22.168-07:00</updated><title type='text'>Bandwidth Test, Speed Test</title><content type='html'>&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;&lt;p&gt;&amp;lt;?php &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;&lt;p&gt;/*** Bandwidth Tester 0.92 ***/ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  /* Please wait for 1.0 patiently! */ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;&lt;p&gt; &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;&lt;p&gt;// How many bytes to test with. Mimimum=70. 128KB=131072. 1MB=1048576 &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  $testsize = 1048576; &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;&lt;p&gt; &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;&lt;p&gt;header (&amp;quot;Expires: Mon, 26 Jul 1997 05:00:00 GMT&amp;quot;);    // Date in the past &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  header (&amp;quot;Last-Modified: &amp;quot; . gmdate(&amp;quot;D, d M Y H:i:s&amp;quot;) . &amp;quot; GMT&amp;quot;); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  // always modified &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  header (&amp;quot;Cache-Control: no-cache, must-revalidate&amp;quot;);  // HTTP/1.1 &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  header (&amp;quot;Pragma: no-cache&amp;quot;);                          // HTTP/1.0 &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  header (&amp;quot;X-Notice: &amp;quot;); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  header (&amp;quot;X-Notice: Bandwidth-Tester is freeware.&amp;quot;); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  header (&amp;quot;X-Notice: You may use it freely on your site.&amp;quot;); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  header (&amp;quot;X-Notice: Just don't remove this notice.&amp;quot;); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  header (&amp;quot;X-Notice: To get the source code, run this script &amp;quot;); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  header (&amp;quot;X-Notice: with downloadme=1 in the query string.&amp;quot;); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  /* How does it work? The script generates a variable amount of random data &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  * sends it to the client and measures the time taken for transmission. The &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  * bandwidth is then calculated from the time using a simple algorithm. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  * &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  * WARNING: This script can bog down your server - as absolutely NO &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  *          optimization was used. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  * &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  * &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  * This script is best run on the Zend PHP Engine, with Zend Optimizer. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  * Any improvement in performance is not guaranteed with other &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  * PHP Engines. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  * &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  * History: &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  *          0.9 - First public release &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  *         0.91 - Reduced the size of the timing code &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  *         0.92 - Reduced the size of the timing code even more &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  * Forecast: &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  *       0.921a - Adding a smaller test before the main to make results more accurate and to adjust test data according to first results &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  *          1.0 - Looking to adding optimization code &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  *          1.1 - Adding template support &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  *          1.2 - Adding web-based administration &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  */ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  if($downloadme==1){ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  echo &amp;quot;&amp;lt;html&amp;gt;&amp;lt;body&amp;gt;&amp;quot;; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  show_source($SCRIPT_FILENAME); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  echo &amp;quot;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&amp;quot;; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  } &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  else { &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;&lt;p&gt;// First, initialize the test comment &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;&lt;p&gt;// seed random &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  srand ((double) microtime() * 1000000); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;&lt;p&gt; &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;&lt;p&gt;if($testsize&amp;lt;70) {die(&amp;quot;&amp;lt;script&amp;gt;alert('The test string size is less than 70. Cannot test.')&amp;lt;/script&amp;gt;&amp;quot;); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  } &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  $realtestsize = $testsize - 70; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  function GetTestString($drealtestsize){ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  $duhteststring = &amp;quot;&amp;lt;!&amp;quot;.&amp;quot;--&amp;quot;; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  for($i=0;$i&amp;lt;$drealtestsize; $i++){ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  $duhteststring .= generatekeycode(); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  } &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  $duhteststring .= &amp;quot;-&amp;quot;.&amp;quot;-&amp;gt;&amp;quot;; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  return $duhteststring; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  } &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  function CalculateBandwidth($Ditt,$Dott){ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  $Datasize=$Dott; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  $LS=$Datasize/$Ditt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  $kbps=(($LS*8)*10*1.02)/10; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  $mbps=$kbps/1024; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  if($mbps&amp;gt;=1){$speed=$mbps.&amp;quot; Mbps aka &amp;quot;.$kbps.&amp;quot; Kbps&amp;quot;;} &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  else {$speed=$kbps.&amp;quot; Kbps aka &amp;quot;.$mbps.&amp;quot; Mbps&amp;quot;;} &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  $speed .=&amp;quot;&amp;lt;br&amp;gt;Time taken to test connection: &amp;quot;.(($Ditt*1024)/1000).&amp;quot; Seconds &amp;lt;br&amp;gt;A number used to determine your speed: &amp;quot;.$LS.&amp;quot;&amp;lt;br&amp;gt;Another number used to determine your speed: &amp;quot;.$Ditt.&amp;quot;&amp;lt;br&amp;gt;Tested your connection with &amp;quot;.$Datasize.&amp;quot;Bytes/&amp;quot;.($Datasize/1024).&amp;quot;KB/&amp;quot;.($Datasize/1048576).&amp;quot;MB of random data&amp;lt;br&amp;gt;&amp;quot;; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  return $speed; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  } &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;&lt;p&gt;function generatekeycode(){ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  // srand ((double) microtime() * 1000000); &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;&lt;p&gt;// Made the randomizer a little more &amp;quot;random&amp;quot;! :) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  srand ((double) microtime() * rand(100000,1000000) / rand(1,15)); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  $tester = rand(33,255); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  if($tester==45)return generatekeycode(); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  return chr($tester); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  } &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  ?&amp;gt;&amp;lt;html&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &amp;lt;head&amp;gt;&amp;lt;title&amp;gt;Bandwidth Tester&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &amp;lt;body&amp;gt;&amp;lt;?php &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  if($HTTP_SERVER_VARS[&amp;quot;REQUEST_METHOD&amp;quot;]==&amp;quot;GET&amp;quot; &amp;amp;&amp;amp; $HTTP_GET_VARS[&amp;quot;execute&amp;quot;]!=&amp;quot;1&amp;quot;){ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  echo('&amp;lt;form action=&amp;quot;'.$HTTP_SERVER_VARS[&amp;quot;SCRIPT_NAME&amp;quot;].'&amp;quot; method=&amp;quot;GET&amp;quot;&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Click Here To Begin Testing&amp;quot; onClick=&amp;quot;this.value=&amp;quot;Please wait while your request is being processed, it may take a while&amp;quot;&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;execute&amp;quot; value=&amp;quot;1&amp;quot;&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;DO.NOT.CACHE&amp;quot; value=&amp;quot;'.rand(255,65536).'&amp;quot;&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &amp;lt;/form&amp;gt;');} &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  elseif($HTTP_GET_VARS[&amp;quot;execute&amp;quot;]==&amp;quot;1&amp;quot;){ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  $teststring=GetTestString($realtestsize);echo('&amp;lt;form method=&amp;quot;POST&amp;quot; action=&amp;quot;'.$HTTP_SERVER_VARS[&amp;quot;SCRIPT_NAME&amp;quot;].'&amp;quot;&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;td&amp;quot; value=&amp;quot;No Test&amp;quot;&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Please wait while your request is being processed, it may take a while&amp;quot;&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &amp;lt;/form&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &amp;lt;script language=&amp;quot;JavaScript&amp;quot;&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  var Hi = new Date(); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &amp;lt;/script&amp;gt;'.$teststring.'&amp;lt;script language=&amp;quot;JavaScript&amp;quot;&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  var Bye = new Date(); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  var NiHao = new Array(Hi.getTime(),Bye.getTime()); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  var Factor=1024; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  if(NiHao[1]==NiHao[0]) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  Ditt=0; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  else &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  Ditt=(NiHao[1]-NiHao[0])/Factor; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  document.forms[0].elements[0].value=Ditt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  document.forms[0].submit(); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &amp;lt;/script&amp;gt;&amp;lt;p&amp;gt;Tested. Now processing your request....&amp;lt;/p&amp;gt;');} &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  elseif($HTTP_SERVER_VARS[&amp;quot;REQUEST_METHOD&amp;quot;]==&amp;quot;POST&amp;quot;&amp;amp;&amp;amp;$HTTP_POST_VARS[&amp;quot;td&amp;quot;]&amp;gt;0){ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  echo('&amp;lt;p&amp;gt;We have tested your Internet connection.&amp;lt;br&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  The speed to which you connected to us is '.CalculateBandwidth($HTTP_POST_VARS[&amp;quot;td&amp;quot;],$testsize).' &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  Thank you!&amp;lt;br&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &amp;lt;/p&amp;gt;');} &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  elseif($HTTP_SERVER_VARS[&amp;quot;REQUEST_METHOD&amp;quot;]==&amp;quot;POST&amp;quot;&amp;amp;&amp;amp;$HTTP_POST_VARS[&amp;quot;td&amp;quot;]==0){ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  echo('&amp;lt;p&amp;gt;We were unable to test your connection speed.&amp;lt;br&amp;gt;It was too fast to measure.&amp;lt;br&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &amp;lt;a href=&amp;quot;'.$HTTP_SERVER_VARS[&amp;quot;SCRIPT_NAME&amp;quot;].'?execute=1&amp;amp;DO.NOT.CACHE='.rand(255,65536).'&amp;quot; onClick=&amp;quot;this.innerText=\'The system is now generating the random test data to benchmark your connection speed. It will take a while.\'&amp;quot;&amp;gt;If you would like to try testing again, click here.&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &amp;lt;p&amp;gt;'.CalculateBandwidth($HTTP_POST_VARS[&amp;quot;td&amp;quot;],$testsize).'&amp;lt;/p&amp;gt;'); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  } &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  ?&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &amp;lt;/body&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;  &amp;lt;/html&amp;gt;&amp;lt;?php } ?&amp;gt; &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;span style="font-family: arial;font-size:180%;" &gt;&lt;span style="font-weight: bold;"&gt;for more details visit:&lt;br /&gt; &lt;/span&gt;&lt;a style="font-weight: bold;" href="http://www.yourip.zxq.net"&gt;http://www.yourip.zxq.net&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-8288888992689333026?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/8288888992689333026/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=8288888992689333026' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/8288888992689333026'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/8288888992689333026'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/06/bandwidth-test-speed-test.html' title='Bandwidth Test, Speed Test'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-68845543360069889</id><published>2008-06-18T02:37:00.000-07:00</published><updated>2008-06-18T02:39:10.115-07:00</updated><title type='text'>Number of days between two dates</title><content type='html'>&lt;div style="text-align: center; color: rgb(102, 0, 0);"&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;Get Number of Days between two difference dates&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;&lt;p&gt;&amp;lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;  // Set the default timezone to US/Eastern&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;  date_default_timezone_set('US/Eastern');&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;&lt;p&gt;// Will return the number of days between the two dates passed in&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;  function count_days($a, $b) {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;  // First we need to break these dates into their constituent parts:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;  $a_parts = getdate($a);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;  $b_parts = getdate($b);&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;&lt;p&gt; // Now recreate these timestamps, based upon noon on each day&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;  // The specific time doesn't matter but it must be the same each day&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;  $a_new = mktime(12, 0, 0, $a_dt['mon'], $a_dt['mday'], $a_dt['year']);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;  $b_new = mktime(12, 0, 0, $b_dt['mon'], $b_dt['mday'], $b_dt['year']);&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;&lt;p&gt; // Subtract these two numbers and divide by the number of seconds in a&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;  //  day.  Round the result since crossing over a daylight savings time&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;  //  barrier will cause this time to be off by an hour or two.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;  return round(abs($a_new - $b_new) / 86400);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;  }&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;&lt;p&gt;// Prepare a few dates&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;  $date1 = strtotime('12/3/1973 8:13am');&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;  $date2 = strtotime('1/15/1974 10:15pm');&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;  $date3 = strtotime('2/14/2005 1:32pm');&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;&lt;p&gt;// Calculate the differences, they should be 43 &amp;amp; 11353&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;  echo &amp;quot;&amp;lt;p&amp;gt;There are &amp;quot;, count_days($date1, $date2), &amp;quot; days.&amp;lt;/p&amp;gt;&amp;quot;;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;  echo &amp;quot;&amp;lt;p&amp;gt;There are &amp;quot;, count_days($date2, $date3), &amp;quot; days.&amp;lt;/p&amp;gt;&amp;quot;;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; color: rgb(102, 0, 0);"&gt;  ?&amp;gt;&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-68845543360069889?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/68845543360069889/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=68845543360069889' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/68845543360069889'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/68845543360069889'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/06/number-of-days-between-two-dates.html' title='Number of days between two dates'/><author><name>MuhammadFJ</name><uri>http://www.blogger.com/profile/17421095331438147919</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_QjAQxhBh3Q4/SPVKs06LKXI/AAAAAAAABtg/qX6cKCZvxXA/S220/look.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357119732797762613.post-6552916003538019122</id><published>2008-06-18T02:35:00.000-07:00</published><updated>2008-06-18T02:37:04.432-07:00</updated><title type='text'>Calculate date or time difference.</title><content type='html'>&lt;div style="text-align: center;"&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0); font-weight: bold;"&gt; Function to calculate date or time difference.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;&amp;lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;/**&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;&lt;/span&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;&lt;/span&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;* Function to calculate date or time difference. Returns an array or&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;* false on error.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;*&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;* @author MFJ       &amp;lt;faisal.hexa@gmail.com&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;* @copyright    Copyright &amp;amp;copy; 2007, MFJ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;* @link         http://www.gidnetwork.com/b-16.html    Get the date / time difference with PHP&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;* @param        string                                 $start&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;* @param        string                                 $end&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;* @return       array&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;*/&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;function get_time_difference( $start, $end )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;$uts['start']      =    strtotime( $start );&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;$uts['end']        =    strtotime( $end );&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;if( $uts['start']!==-1 &amp;amp;&amp;amp; $uts['end']!==-1 )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;if( $uts['end'] &amp;gt;= $uts['start'] )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;$diff    =    $uts['end'] - $uts['start'];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;if( $days=intval((floor($diff/86400))) )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;$diff = $diff % 86400;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;if( $hours=intval((floor($diff/3600))) )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;$diff = $diff % 3600;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;if( $minutes=intval((floor($diff/60))) )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;$diff = $diff % 60;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;$diff    =    intval( $diff ); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;return( array('days'=&amp;gt;$days, 'hours'=&amp;gt;$hours, 'minutes'=&amp;gt;$minutes, 'seconds'=&amp;gt;$diff) );&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;trigger_error( &amp;quot;Ending date/time is earlier than the start date/time&amp;quot;, E_USER_WARNING );&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;trigger_error( &amp;quot;Invalid date/time data detected&amp;quot;, E_USER_WARNING );&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;return( false );&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic; color: rgb(102, 0, 0);"&gt;?&amp;gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4357119732797762613-6552916003538019122?l=apniphp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apniphp.blogspot.com/feeds/6552916003538019122/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4357119732797762613&amp;postID=6552916003538019122' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/6552916003538019122'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357119732797762613/posts/default/6552916003538019122'/><link rel='alternate' type='text/html' href='http://apniphp.blogspot.com/2008/06/calculate-date-or-time-difference.html' title='Calculate date or time difference.'/><author><
