<?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>Bill Richards &#187; PHP</title>
	<atom:link href="http://www.wrichards.com/blog/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wrichards.com/blog</link>
	<description>a developer&#039;s blog</description>
	<lastBuildDate>Tue, 20 Jul 2010 16:32:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PHP base_convert() in AS3</title>
		<link>http://www.wrichards.com/blog/2010/07/php-base_convert-in-as3/</link>
		<comments>http://www.wrichards.com/blog/2010/07/php-base_convert-in-as3/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 16:10:39 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[base_convert()]]></category>

		<guid isPermaLink="false">http://www.wrichards.com/blog/?p=109</guid>
		<description><![CDATA[Here is a quick example of how to use PHP&#8217;s base convert function in AS3. A lot of people use this function for shorter masked URLs like YouTube. Easy enough but took me a minute to find the equivalent in actionscript. PHP: function encode36($x){ return base_convert($x, 10, 36); } function decode36($x){ return base_convert($x, 36, 10); [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a quick example of how to use PHP&#8217;s base convert function in AS3. A lot of people use this function for shorter masked URLs like YouTube. Easy enough but took me a minute to find the equivalent in actionscript.</p>
<p>PHP:</p>
<pre name="code" class="php">
function encode36($x){
    return base_convert($x, 10, 36);
}
function decode36($x){
    return base_convert($x, 36, 10);
}
</pre>
<p>Actionscript 3:</p>
<pre name="code" class="javascript">
function encode36(x:Number):String{
    return x.toString(36);
}
function decode36(x:String):int {
    return parseInt(x,36);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.wrichards.com/blog/2010/07/php-base_convert-in-as3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: Check if a URL exists with cURL</title>
		<link>http://www.wrichards.com/blog/2009/05/php-check-if-a-url-exists-with-curl/</link>
		<comments>http://www.wrichards.com/blog/2009/05/php-check-if-a-url-exists-with-curl/#comments</comments>
		<pubDate>Wed, 27 May 2009 11:44:34 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[cURL]]></category>

		<guid isPermaLink="false">http://www.wrichards.com/blog/?p=90</guid>
		<description><![CDATA[In my previous post about email validation one user pointed out that this will not actually validate if a website&#8217;s domain actually exists. Here is a simple function that will do just that, determine if a website exists using PHP and cURL. Edit: After searching a bit, I found another similar cURL solution that checks [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous post about <a href="http://www.wrichards.com/blog/2009/02/php-email-validation/">email validation</a> one user pointed out that this will not actually validate if a website&#8217;s domain actually exists. Here is a simple function that will do just that, determine if a website exists using PHP and cURL.</p>
<p>Edit: After searching a bit, I found another <a href="http://www.jellyandcustard.com/2006/05/31/determining-if-a-url-exists-with-curl/">similar cURL solution</a> that checks the actual headers. Since cURL can return HTTP code I don&#8217;t think all that extra code is necessary? I could be wrong!</p>
<pre name="code" class="php">
function urlExists($url=NULL)
	{
		if($url == NULL) return false;
		$ch = curl_init($url);
		curl_setopt($ch, CURLOPT_TIMEOUT, 5);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		$data = curl_exec($ch);
		$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
		curl_close($ch);
		if($httpcode>=200 &#038;&#038; $httpcode<300){
			return true;
		} else {
			return false;
		}
	}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.wrichards.com/blog/2009/05/php-check-if-a-url-exists-with-curl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Upcoming Birthdays From MySQL</title>
		<link>http://www.wrichards.com/blog/2009/03/getting-upcoming-birthdays-from-mysql/</link>
		<comments>http://www.wrichards.com/blog/2009/03/getting-upcoming-birthdays-from-mysql/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 23:51:52 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[birthday]]></category>
		<category><![CDATA[usort()]]></category>

		<guid isPermaLink="false">http://www.wrichards.com/blog/?p=85</guid>
		<description><![CDATA[Assuming you have a table called `users` with birthday as `bday` for the column name, this will pull all users who are having a birthday in the next 7 days. This is very useful if you want to showcase your member&#8217;s birthdays on your website. SELECT * FROM `users` WHERE DAYOFYEAR(curdate()) = dayofyear(`bday`) LIMIT 30; [...]]]></description>
			<content:encoded><![CDATA[<p>Assuming you have a table called `users` with birthday as `bday` for the column name, this will pull all users who are having a birthday in the next 7 days. This is very useful if you want to showcase your member&#8217;s birthdays on your website.</p>
<pre name="code" class="php">
SELECT * FROM `users` WHERE  DAYOFYEAR(curdate()) <= dayofyear(`bday`) AND DAYOFYEAR(curdate()) +7 >= dayofyear(`bday`) LIMIT 30;
</pre>
<p>There is of course one small problem with this, it&#8217;s not sorted. If we sort by `bday` ASC it&#8217;ll still be off since user&#8217;s are born on different years. What we really want is to sort by month and day only. I&#8217;m sure this can be done in MySQL but here is a PHP solution to take care of it.</p>
<pre name="code" class="php">
$sql = "SELECT * FROM `users` WHERE  DAYOFYEAR(curdate()) <= dayofyear(`bday`) AND DAYOFYEAR(curdate()) +7 >= dayofyear(`bday`) LIMIT 30;";
$query = mysql_query($sql);
$rows = mysql_num_rows($query);
if(!empty($rows)){
	while($resultFind = mysql_fetch_array($query)){
		$arr[] = array('bday' => $resultFind['bday'], 'bday2' => date("md", strtotime($resultFind['bday'])));
	}
}

function compare($x, $y) {
	if ( $x["bday2"] == $y["bday2"] )
	 return 0;
	else if ( $x["bday2"] < $y["bday2"] )
	 return -1;
	else
	 return 1;
}

usort($arr, "compare");
</pre>
<p>Using usort() we can sort based on the month and day. You now have your list sorted <img src='http://www.wrichards.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.wrichards.com/blog/2009/03/getting-upcoming-birthdays-from-mysql/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHP5 Email Validation</title>
		<link>http://www.wrichards.com/blog/2009/02/php-email-validation/</link>
		<comments>http://www.wrichards.com/blog/2009/02/php-email-validation/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 01:44:20 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[email validation]]></category>

		<guid isPermaLink="false">http://www.wrichards.com/blog/?p=26</guid>
		<description><![CDATA[In prior version of PHP you had to use some regex solution to validate an email address, now in PHP5 it&#8217;s as simple as: function isValidEmail($email){ return filter_var(filter_var($email, FILTER_SANITIZE_EMAIL), FILTER_VALIDATE_EMAIL); } if(isValidEmail('email@domain.com')){ //valid } else { //not valid } I&#8217;ve been using PHP5 ever since it was released but didn&#8217;t look into the PECL Filter [...]]]></description>
			<content:encoded><![CDATA[<p>In prior version of PHP you had to use some regex solution to validate an email address, now in PHP5 it&#8217;s as simple as:</p>
<pre name="code" class="php">function isValidEmail($email){
 return filter_var(filter_var($email, FILTER_SANITIZE_EMAIL), FILTER_VALIDATE_EMAIL);
}

if(isValidEmail('email@domain.com')){
//valid
} else {
//not valid
}</pre>
<p>I&#8217;ve been using PHP5 ever since it was released but didn&#8217;t look into the PECL Filter extension until recently. Pretty handy.</p>
<p>Please note that I also added the <a title="FILTER_SANITIZE_EMAIL filter" href="http://www.w3schools.com/php/filter_sanitize_email.asp" target="_blank">FILTER_SANITIZE_EMAIL</a> filter which removes all illegal e-mail characters from a string. This is not needed if you only want to validate and not clean the input. <img src='http://www.wrichards.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.wrichards.com/blog/2009/02/php-email-validation/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Sphinx : A MySQL full-text search engine</title>
		<link>http://www.wrichards.com/blog/2009/02/sphinx-mysql-php/</link>
		<comments>http://www.wrichards.com/blog/2009/02/sphinx-mysql-php/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 01:00:39 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[sphinx]]></category>

		<guid isPermaLink="false">http://www.wrichards.com/blog/?p=19</guid>
		<description><![CDATA[This has got to be one of the coolest things I have come across in a long time. Sphinx a standalone MySQL full-text search engine. I&#8217;ve been working with it for a couple weeks now and I must say, this thing is blazin&#8217; fast. I was most impressed by performance on large data sets (60+ [...]]]></description>
			<content:encoded><![CDATA[<p><a title="http://www.sphinxsearch.com/" href="http://www.sphinxsearch.com/" target="_blank"><img src="http://www.sphinxsearch.com/g/sphinx.jpg" alt="Sphinx - Standalone MySQL Full-text search" style="float:left" /></a> This has got to be one of the coolest things I have come across in a long time. <a href="http://www.sphinxsearch.com/">Sphinx</a> a standalone MySQL full-text search engine. I&#8217;ve been working with it for a couple weeks now and I must say, this thing is blazin&#8217; fast. I was most impressed by performance on large data sets (60+ million rows). Even when preforming sorts, it&#8217;s really fast. Oh, they have a <a title="PHP API" href="http://www.sphinxsearch.com/wiki/doku.php?id=php_api_docs" target="_blank">PHP API</a> too! If you&#8217;re looking to super charge your mysql search, give it a shot!</p>
<p>More on this with examples later.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wrichards.com/blog/2009/02/sphinx-mysql-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
