<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Coders Cult Web Development Blog &#187; PHP Programming</title>
	<atom:link href="http://coderscult.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://coderscult.com</link>
	<description>Website development - HTML/XHTML, CSS, Javascript/AJAX, PHP, MySQL</description>
	<lastBuildDate>Thu, 31 Dec 2009 12:58:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP cURL Cookies Example</title>
		<link>http://coderscult.com/php/php-curl/2008/05/20/php-curl-cookies-example/</link>
		<comments>http://coderscult.com/php/php-curl/2008/05/20/php-curl-cookies-example/#comments</comments>
		<pubDate>Tue, 20 May 2008 13:01:00 +0000</pubDate>
		<dc:creator>Mike Lopez</dc:creator>
				<category><![CDATA[PHP cURL]]></category>
		<category><![CDATA[PHP Programming]]></category>

		<guid isPermaLink="false">http://coderscult.com/?p=42</guid>
		<description><![CDATA[






Want to learn how to use PHP cURL with Cookies?  Well, it&#8217;s pretty simple so let&#8217;s go see the code but first let&#8217;s make a scenario&#8230;
Say we have a page called &#8216;cookiepage.php&#8217; in a particular website that checks for the cookie set by the homepage and will only return the proper output if the [...]]]></description>
			<content:encoded><![CDATA[<p>Want to learn how to use PHP cURL with Cookies?  Well, it&#8217;s pretty simple so let&#8217;s go see the code but first let&#8217;s make a scenario&#8230;</p>
<p>Say we have a page called &#8216;cookiepage.php&#8217; in a particular website that checks for the cookie set by the homepage and will only return the proper output if the cookie exists.  How do you do it?  Here&#8217;s how&#8230;</p>
<p><span id="more-42"></span></p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span><br />
<span class="coMULTI">/* STEP 1. let&#8217;s create a cookie file */</span><br />
<span class="re0">$ckfile</span> = <a href="http://www.php.net/tempnam"><span class="kw3">tempnam</span></a> <span class="br0">&#40;</span><span class="st0">&quot;/tmp&quot;</span>, <span class="st0">&quot;CURLCOOKIE&quot;</span><span class="br0">&#41;</span>;</p>
<p><span class="coMULTI">/* STEP 2. visit the homepage to set the cookie properly */</span><br />
<span class="re0">$ch</span> = curl_init <span class="br0">&#40;</span><span class="st0">&quot;http://somedomain.com/&quot;</span><span class="br0">&#41;</span>;<br />
curl_setopt <span class="br0">&#40;</span><span class="re0">$ch</span>, CURLOPT_COOKIEJAR, <span class="re0">$ckfile</span><span class="br0">&#41;</span>; <br />
curl_setopt <span class="br0">&#40;</span><span class="re0">$ch</span>, CURLOPT_RETURNTRANSFER, <span class="kw2">true</span><span class="br0">&#41;</span>;<br />
<span class="re0">$output</span> = curl_exec <span class="br0">&#40;</span><span class="re0">$ch</span><span class="br0">&#41;</span>;</p>
<p><span class="coMULTI">/* STEP 3. visit cookiepage.php */</span><br />
<span class="re0">$ch</span> = curl_init <span class="br0">&#40;</span><span class="st0">&quot;http://somedomain.com/cookiepage.php&quot;</span><span class="br0">&#41;</span>;<br />
curl_setopt <span class="br0">&#40;</span><span class="re0">$ch</span>, CURLOPT_COOKIEFILE, <span class="re0">$ckfile</span><span class="br0">&#41;</span>; <br />
curl_setopt <span class="br0">&#40;</span><span class="re0">$ch</span>, CURLOPT_RETURNTRANSFER, <span class="kw2">true</span><span class="br0">&#41;</span>;<br />
<span class="re0">$output</span> = curl_exec <span class="br0">&#40;</span><span class="re0">$ch</span><span class="br0">&#41;</span>;</p>
<p><span class="coMULTI">/* here you can do whatever you want with $output */</span><br />
<span class="kw2">?&gt;</span></div>
<p>Just in case you weren&#8217;t able to catch what we did in the above example, here&#8217;s a short explanation.</p>
<ul>
<li>STEP 1 creates a temporary cookie file using the tempnam() function.</li>
<li>STEP 2 loads the homepage and saves the cookie in our temporary cookie file. The key here is this line:
<p><strong>curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);</strong>
</li>
<li>STEP 3 loads cookiepage.php with the saved cookie with this line:
<p><strong>curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile);</strong>
</li>
</ul>
<p>Sleek and simple ei?  Hope this PHP cURL Cookie example helped you out!</p>
]]></content:encoded>
			<wfw:commentRss>http://coderscult.com/php/php-curl/2008/05/20/php-curl-cookies-example/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>How to Post Data with cURL in PHP</title>
		<link>http://coderscult.com/php/php-curl/2008/05/20/how-to-post-data-with-curl-in-php/</link>
		<comments>http://coderscult.com/php/php-curl/2008/05/20/how-to-post-data-with-curl-in-php/#comments</comments>
		<pubDate>Tue, 20 May 2008 12:10:26 +0000</pubDate>
		<dc:creator>Mike Lopez</dc:creator>
				<category><![CDATA[PHP cURL]]></category>
		<category><![CDATA[PHP Programming]]></category>

		<guid isPermaLink="false">http://coderscult.com/?p=40</guid>
		<description><![CDATA[Do you need to post data to a website using PHP?  It&#8217;s actually pretty easy to do.  Here&#8217;s the code.
&#60;?php
$urltopost = &#34;http://somewebsite.com/script.php&#34;;
$datatopost = array &#40;
&#34;firstname&#34; =&#62; &#34;Mike&#34;,
&#34;lastname&#34; =&#62; &#34;Lopez&#34;,
&#34;email&#34; =&#62; &#34;my@email.com&#34;,
&#41;;
&#60;span id=&#34;more-40&#34;&#62;&#60;/span&#62;
$ch = curl_init &#40;$urltopost&#41;;
curl_setopt &#40;$ch, CURLOPT_POST, true&#41;;
curl_setopt &#40;$ch, CURLOPT_POSTFIELDS, $datatopost&#41;;
curl_setopt &#40;$ch, CURLOPT_RETURNTRANSFER, true&#41;;
$returndata = curl_exec &#40;$ch&#41;;
?&#62;
And what happened?  Here&#8217;s my quick [...]]]></description>
			<content:encoded><![CDATA[<p>Do you need to post data to a website using PHP?  It&#8217;s actually pretty easy to do.  Here&#8217;s the code.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span><br />
<span class="re0">$urltopost</span> = <span class="st0">&quot;http://somewebsite.com/script.php&quot;</span>;<br />
<span class="re0">$datatopost</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a> <span class="br0">&#40;</span><br />
<span class="st0">&quot;firstname&quot;</span> =&gt; <span class="st0">&quot;Mike&quot;</span>,<br />
<span class="st0">&quot;lastname&quot;</span> =&gt; <span class="st0">&quot;Lopez&quot;</span>,<br />
<span class="st0">&quot;email&quot;</span> =&gt; <span class="st0">&quot;my@email.com&quot;</span>,<br />
<span class="br0">&#41;</span>;</p>
<p>&lt;span id=<span class="st0">&quot;more-40&quot;</span>&gt;&lt;/span&gt;</p>
<p><span class="re0">$ch</span> = curl_init <span class="br0">&#40;</span><span class="re0">$urltopost</span><span class="br0">&#41;</span>;<br />
curl_setopt <span class="br0">&#40;</span><span class="re0">$ch</span>, CURLOPT_POST, <span class="kw2">true</span><span class="br0">&#41;</span>;<br />
curl_setopt <span class="br0">&#40;</span><span class="re0">$ch</span>, CURLOPT_POSTFIELDS, <span class="re0">$datatopost</span><span class="br0">&#41;</span>;<br />
curl_setopt <span class="br0">&#40;</span><span class="re0">$ch</span>, CURLOPT_RETURNTRANSFER, <span class="kw2">true</span><span class="br0">&#41;</span>;<br />
<span class="re0">$returndata</span> = curl_exec <span class="br0">&#40;</span><span class="re0">$ch</span><span class="br0">&#41;</span>;<br />
<span class="kw2">?&gt;</span></div>
<p>And what happened?  Here&#8217;s my quick explanation.</p>
<p><strong>$urltopost</strong></p>
<blockquote><p>The url where you want to post your data to</p></blockquote>
<p><strong>$datatopost</strong></p>
<blockquote><p>The post data as an associative array.  The keys are the post variables</p></blockquote>
<p><strong>$ch = curl_init ($urltopost);</strong></p>
<blockquote><p>Initializes cURL</p></blockquote>
<p><strong>curl_setopt ($ch, CURLOPT_POST, true);</strong></p>
<blockquote><p>Tells cURL that we want to send post data</p></blockquote>
<p><strong>curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);</strong></p>
<blockquote><p>Tells cURL what are post data is</p></blockquote>
<p><strong>curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);</strong></p>
<blockquote><p>Tells cURL to return the output of the post</p></blockquote>
<p><strong>$returndata = curl_exec ($ch);</strong></p>
<blockquote><p>Executes the cURL and saves theoutput in $returndata</p></blockquote>
<p>There ya go!  If you have questions, <a href="http://forums.coderscult.com/index.php/topic,140.new.html">just ask in our forum</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://coderscult.com/php/php-curl/2008/05/20/how-to-post-data-with-curl-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP cURL Tutorial and Example</title>
		<link>http://coderscult.com/php/php-curl/2008/05/20/php-curl-tutorial-and-example/</link>
		<comments>http://coderscult.com/php/php-curl/2008/05/20/php-curl-tutorial-and-example/#comments</comments>
		<pubDate>Tue, 20 May 2008 12:04:00 +0000</pubDate>
		<dc:creator>Mike Lopez</dc:creator>
				<category><![CDATA[PHP cURL]]></category>
		<category><![CDATA[PHP Programming]]></category>

		<guid isPermaLink="false">http://coderscult.com/?p=41</guid>
		<description><![CDATA[Do you want to learn how to use cURL in PHP?  Well, if so then this tutorial is for you.  But before anything else, what is cURL?
cURL is a command line tool for transferring files with URL syntax. The strong point of cURL is the number of data transfer protocols it supports. It [...]]]></description>
			<content:encoded><![CDATA[<p>Do you want to learn how to use cURL in PHP?  Well, if so then this tutorial is for you.  But before anything else, what is cURL?</p>
<blockquote><p>cURL is a command line tool for transferring files with URL syntax. The strong point of cURL is the number of data transfer protocols it supports. It is distributed under the MIT License which makes cURL free software.  It supports FTP, FTPS, HTTP, HTTPS, TFTP, SCP, SFTP, Telnet, DICT, FILE and LDAP. &#8211; <a href="http://en.wikipedia.org/wiki/CURL" target="_blank">based on Wikipedia&#8217;s definition</a></p></blockquote>
<p><span id="more-41"></span></p>
<p>PHP cURL allows you to read websites, make automated logins, upload files and many more.  I&#8217;m personally using it to automate updating of my many websites.</p>
<p>Now that you know what cURL is, I think it&#8217;s time to look at some code.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span><br />
<span class="re0">$ch</span> = curl_init <span class="br0">&#40;</span><span class="st0">&quot;http://www.yahoo.com&quot;</span><span class="br0">&#41;</span>;<br />
curl_setopt <span class="br0">&#40;</span><span class="re0">$ch</span>, CURLOPT_RETURNTRANSFER, <span class="kw2">true</span><span class="br0">&#41;</span>;<br />
<span class="re0">$yahoo</span> = curl_exec <span class="br0">&#40;</span><span class="re0">$ch</span><span class="br0">&#41;</span>;<br />
<span class="kw2">?&gt;</span></div>
<p>The simple example above simply gets the contents of <strong>www.yahoo.com</strong> and saves it in the variable <strong>$yahoo</strong>.  Here&#8217;s a line-by-line explanation:</p>
<p><strong>$ch = curl_init (&quot;http://www.yahoo.com&quot;);</strong></p>
<blockquote><p>Initialize curl with the URL of yahoo</p></blockquote>
<p><strong>curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);</strong></p>
<blockquote><p>Tell php curl that we want the data returned to us instead of being displayed</p></blockquote>
<p><strong>$yahoo = curl_exec ($ch);</strong></p>
<blockquote><p>Execute curl and put the output in $yahoo.</p></blockquote>
<p>But, that&#8217;s too simple!  That can be done in simpler ways with PHP&#8217;s file functions such as file() and file_get_contents()!  True but that&#8217;s where the comparison ends.</p>
<p>The power of PHP cURL lies within the curl_setopt() function.  This function instructs cURL of what exactly we want to do.  Let&#8217;s say, what if a webpage that you want to access checks for the HTTP_REFERER header?  Or perhaps, what if you need to access a webpage that works correctly only if cookies are enabled?</p>
<p>Here&#8217;s another example&#8230; This time we specify the HTTP_REFERER&#8230;</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span><br />
<span class="re0">$ch</span> = curl_init <span class="br0">&#40;</span><span class="st0">&quot;http://www.somedomain.com/page2.php&quot;</span><span class="br0">&#41;</span>;<br />
curl_setopt <span class="br0">&#40;</span><span class="re0">$ch</span>, CURLOPT_RETURNTRANSFER, <span class="kw2">true</span><span class="br0">&#41;</span>;<br />
curl_setopt <span class="br0">&#40;</span><span class="re0">$ch</span>, CURLOPT_REFERER, <span class="st0">&quot;http://www.somedomain.com/page1.php&quot;</span><span class="br0">&#41;</span>;<br />
<span class="re0">$page</span> = curl_exec <span class="br0">&#40;</span><span class="re0">$ch</span><span class="br0">&#41;</span>;<br />
<span class="kw2">?&gt;</span></div>
<p>In this example, the CURLOPT_REFERER line tells cURL to set the HTTP_REFERER header to http://www.somedomain.com/page1.php.</p>
<p>PHP cURL can do more.  It can send POST data, it can log on to a website and automate tasks as if it was a real person and much more.  That&#8217;s it for now and I hope this PHP cURL Tutorial helped you.</p>
]]></content:encoded>
			<wfw:commentRss>http://coderscult.com/php/php-curl/2008/05/20/php-curl-tutorial-and-example/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Setting up your PHP Development Environment</title>
		<link>http://coderscult.com/php/2008/03/26/setting-up-your-php-development-environment/</link>
		<comments>http://coderscult.com/php/2008/03/26/setting-up-your-php-development-environment/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 19:34:04 +0000</pubDate>
		<dc:creator>Mike Lopez</dc:creator>
				<category><![CDATA[PHP Programming]]></category>

		<guid isPermaLink="false">http://coderscult.com/php/2008/03/26/setting-up-your-php-development-environment/</guid>
		<description><![CDATA[I realized that a lot of people who want to learn PHP are having hard time getting started with it &#8211; not because PHP is difficult to use or understand but simply because they don&#8217;t know where to start.  Because of this, I decided to write this short how-to on getting started with PHP. [...]]]></description>
			<content:encoded><![CDATA[<p>I realized that a lot of people who want to learn PHP are having hard time getting started with it &#8211; not because PHP is difficult to use or understand but simply because they don&#8217;t know where to start.  Because of this, I decided to write this short how-to on getting started with PHP.  It covers all the necessary stuff to setup Apache, PHP, and MySQL as well as to install one of my favorite PHP editors.</p>
<p><span id="more-22"></span></p>
<p>Without further ado, let&#8217;s go on&#8230;</p>
<p>The simplest way to install everything you need to run PHP web pages on your workstation is to install <a href="http://www.apachefriends.org/en/index.html">XAMPP</a>.  The beauty of using XAMPP is that it can be installed on any of the following operating systems:<br />
<img src='http://coderscult.com/wp-content/uploads/2008/03/xampplogo.jpg' alt='XAMPP Logo' align="right" hspace="5" />
<ul>
<li>Microsoft Windows</li>
<li>Linux</li>
<li>Sun Solaris</li>
<li>Mac OS X</li>
</ul>
<p>As for XAMPP, it means:</p>
<ul>
<li>X &#8211; any of the four operating systems above</li>
<li>A &#8211; Apache (the web server that serves your PHP web pages)</li>
<li>M &#8211; MySQL (the SQL database)</li>
<li>P &#8211; PHP</li>
<li>P &#8211; Perl</li>
</ul>
<p>It used to be called LAMPP where L stands for Linux but they decided to change L with X since it&#8217;s not just Linux anymore.  So how do we install it?  Simple, go to <a href="http://www.apachefriends.org/en/xampp.html">http://www.apachefriends.org/en/xampp.html</a> and download the correct installer for your system.  To make it even easier for you, I&#8217;m including the links to the installer download pages here.</p>
<ul>
<li>Linux &#8211; <a href="http://www.apachefriends.org/en/xampp-linux.html">http://www.apachefriends.org/en/xampp-linux.html</a></li>
<li>Microsoft Windows &#8211; <a href="http://www.apachefriends.org/en/xampp-windows.html">http://www.apachefriends.org/en/xampp-windows.html</a></li>
<li>Mac OS X &#8211; <a href="http://www.apachefriends.org/en/xampp-macosx.html">http://www.apachefriends.org/en/xampp-macosx.html</a></li>
<li>Sun Solaris &#8211; <a href="http://www.apachefriends.org/en/xampp-solaris.html">http://www.apachefriends.org/en/xampp-solaris.html</a></li>
</ul>
<p>To install, just download and follow installation instructions.  (C&#8217;mon, you don&#8217;t expect me to spoon-feed you everything right?)</p>
<p>After you&#8217;ve installed XAMPP, all you need to do is run it.  In Windows, all you have to do is run XAMPP Control and start each service that you want.  Basically, you&#8217;ll want to start Apache and MySQL.  After you&#8217;ve started Apache, you can now give it a try by browsing to http://localhost/.  That should show you the XAMPP welcome page.</p>
<p align="center"><img src='http://coderscult.com/wp-content/uploads/2008/03/xamppcontrol.png' alt='XAMPP Control Panel' /><br />
The XAMPP Control Panel</p>
<p align="center"><img src='http://coderscult.com/wp-content/uploads/2008/03/xamppstartup.png' alt='XAMPP Start Page' /><br />
XAMPP Start Page (http://localhost/)</p>
<p>XAMPP also comes with <a href="http://www.google.com.ph/url?sa=t&#038;ct=res&#038;cd=1&#038;url=http%3A%2F%2Fwww.phpmyadmin.net%2F&#038;ei=e57qR_-0KoSmpwSipb3xCQ&#038;usg=AFQjCNEVUIHBxbZboIeYNUd_4abvz6M1zw&#038;sig2=rwttWWCaOVTwJdySnUFucA">phpMyAdmin</a> which allows you to manage your MySQL databases via browser interface.  You may access phpMyAdmin by browsing to http://localhost/phpmyadmin</p>
<p align="center"><img src='http://coderscult.com/wp-content/uploads/2008/03/phpmyadmin.png' alt='phpMyAdmin' /><br />
phpMyAdmin (http://localhost/phpmyadmin)</p>
<p>So where do you put your PHP pages so that they are properly served by Apache?  With XAMPP, it goes in the htdocs folder of your XAMPP installation.  I recommend that you create separate folders for your projects so you can easily manage them.</p>
<p>Now that you have Apache/PHP and MySQL running through XAMPP, the next thing for you to do is install an editor.  Any plain text editor such as Notepad will do.  However, there are better editors out there that provide syntax highlighting and debugging functions.  One of my favorites is <a href="http://www.eclipse.org/pdt/">Eclipse PDT (PHP Development Tools)</a>.  It runs on Java which means it is cross-platform.</p>
<p align="center"><img src='http://coderscult.com/wp-content/uploads/2008/03/eclipse-splash.png' alt='Eclipse PDT Splash Screen' /><br />
Eclipse Splash Screen</p>
<p>The easiest way to install Eclipse PDT is to follow these simple steps:</p>
<ol>
<li>Go to <a href="http://download.eclipse.org/tools/pdt/downloads/">http://download.eclipse.org/tools/pdt/downloads/</a></li>
<li>Click the Release Build</li>
<li>Download the All-in-One package for your operating system</li>
<li>Uncompress the downloaded package and run Eclipse from there</li>
</ol>
<p>If you did it correctly, then you should see Eclipse&#8217;s IDE.  Mine looks something like this:</p>
<p align="center"><img src='http://coderscult.com/wp-content/uploads/2008/03/eclipse-ide.png' alt='Eclipse PDT Intergrated Development Environment' /><br />
Eclipse PDT Integrated Development Environment</p>
<p>One nice feature I like with Eclipse PDT is that it has a list of all the functions supported by PHP making it easier for me to write thousands of lines of code.  Also, since it&#8217;s an IDE, it also keeps track of your variables, functions, and classes.</p>
<p>Quick but important note, it&#8217;s also best to keep a copy of the PHP manual accessible.  If you&#8217;re always online, then the manual is just a click away.  Typing php.net/str_replace on your browser will take you to the documentation of the PHP&#8217;s str_replace function.  You may also want to <a href="http://docs.php.net/download-docs.php">download a copy of the PHP manual</a> if you&#8217;re not connected to the internet all the time.</p>
<p>There you go.  If you&#8217;ve successfully installed XAMPP and Eclipse then you already have the basic needs in getting started with PHP.</p>
]]></content:encoded>
			<wfw:commentRss>http://coderscult.com/php/2008/03/26/setting-up-your-php-development-environment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Date Validation Using strtotime()</title>
		<link>http://coderscult.com/php/2008/03/12/php-date-validation-using-strtotime/</link>
		<comments>http://coderscult.com/php/2008/03/12/php-date-validation-using-strtotime/#comments</comments>
		<pubDate>Wed, 12 Mar 2008 21:10:38 +0000</pubDate>
		<dc:creator>Mike Lopez</dc:creator>
				<category><![CDATA[PHP Programming]]></category>

		<guid isPermaLink="false">http://coderscult.com/2008/03/12/php-date-validation-using-strtotime/</guid>
		<description><![CDATA[Here&#8217;s a nifty little script I use to validate date input with PHP.  This function can accept any common date entry and return true if the date is valid or false otherwise.
The Script
&#60;?php
&#60;span id=&#34;more-5&#34;&#62;&#60;/span&#62;
function isValidDate &#40;$dateString&#41; &#123;
&#160; &#160; &#160; &#160; $x = strtotime &#40;$dateString&#41;;
&#160; &#160; &#160; &#160; if &#40;$x === false &#124;&#124; $x == [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a nifty little script I use to validate date input with PHP.  This function can accept any common date entry and return true if the date is valid or false otherwise.</p>
<p>The Script</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span></p>
<p>&lt;span id=<span class="st0">&quot;more-5&quot;</span>&gt;&lt;/span&gt;</p>
<p><span class="kw2">function</span> isValidDate <span class="br0">&#40;</span><span class="re0">$dateString</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$x</span> = <a href="http://www.php.net/strtotime"><span class="kw3">strtotime</span></a> <span class="br0">&#40;</span><span class="re0">$dateString</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$x</span> === <span class="kw2">false</span> || <span class="re0">$x</span> == <span class="nu0">-1</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="coMULTI">/* usage */</span><br />
isValidDate <span class="br0">&#40;</span><span class="st0">&quot;March 18, 1977&quot;</span><span class="br0">&#41;</span>; &nbsp;<span class="co1">// returns true</span><br />
isValidDate <span class="br0">&#40;</span><span class="st0">&quot;tomorrow&quot;</span><span class="br0">&#41;</span>; &nbsp;<span class="co1">// returns true</span><br />
isValidDate <span class="br0">&#40;</span><span class="st0">&quot;+1 Month&quot;</span><span class="br0">&#41;</span>; &nbsp;<span class="co1">// returns true</span><br />
isValidDate <span class="br0">&#40;</span><span class="st0">&quot;Invalid Date Here&quot;</span><span class="br0">&#41;</span>; <span class="co1">// returns false;</span></p>
<p><span class="kw2">?&gt;</span></div>
<p>Since this isValidDate uses PHP&#8217;s strtotime function, it can practically accept any English textual datetime description.</p>
]]></content:encoded>
			<wfw:commentRss>http://coderscult.com/php/2008/03/12/php-date-validation-using-strtotime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
