<?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>Full On Design &#187; PHP</title>
	<atom:link href="http://www.fullondesign.co.uk/category/coding/php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.fullondesign.co.uk</link>
	<description>Design &#38; Web Technologies</description>
	<lastBuildDate>Mon, 21 Jun 2010 16:45:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>How to use the Filter Functions in PHP</title>
		<link>http://www.fullondesign.co.uk/coding/php/1456-how-to-use-the-filter-functions-in-php.htm</link>
		<comments>http://www.fullondesign.co.uk/coding/php/1456-how-to-use-the-filter-functions-in-php.htm#comments</comments>
		<pubDate>Mon, 21 Jun 2010 16:44:58 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.fullondesign.co.uk/?p=1456</guid>
		<description><![CDATA[When I started learning PHP (Back in the PHP4 days) validating data was always a pain (for me at least). Most of the resources available cited the POSIX functions as the most effective way of validating an email address or URL. Thankfully since then, the PHP community has embraced the PCRE functions which are more efficient and [...]]]></description>
			<content:encoded><![CDATA[<p>When I started learning PHP (Back in the PHP4 days) validating data was always a pain (for me at least). Most of the resources available cited the <a href="http://uk3.php.net/manual/en/ref.regex.php">POSIX functions</a> as the most effective way of validating an email address or URL.</p>
<p>Thankfully since then, the PHP community has embraced the <a href="http://uk3.php.net/manual/en/ref.pcre.php">PCRE functions</a> which are more efficient and are Perl-compatible. However the downside to PCRE (and POSIX for that matter) is that you need to know <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expressions</a>, which for a newbie to learn can feel like walking through a minefield.</p>
<p>Recently though the <a href="http://www.php.net/manual/en/ref.filter.php">Filter Functions</a> have become a very popular method to validate data. This is due to their small learning curve.</p>
<h3>How to use the Filter Functions</h3>
<p>In this example (Using the <a href="http://www.php.net/manual/en/function.filter-var.php">filter_var()</a> function) the filter function takes the data you input (For example: email@example.com) and will return either the data (if it&#8217;s valid) or false (if the data is not valid).</p>
<p><span id="more-1456"></span></p>
<p>
<pre class="brush: php;">&lt;?php
// Filter an Email Address
var_dump(filter_var('email@example.com', FILTER_VALIDATE_EMAIL)); // Returns: string(17) &quot;email@example.com&quot;

// This is a fake email being filtered.
var_dump(filter_var('fake_mail.com', FILTER_VALIDATE_EMAIL)); // Returns: bool(false)

var_dump(filter_var('ema(i)l@e\xample.com', FILTER_SANITIZE_EMAIL )); // Returns: string(17) &quot;email@example.com&quot;

// Filter a URL
var_dump(filter_var('example.com', FILTER_VALIDATE_URL)); // Returns: bool(false)

// Filter a URL
var_dump(filter_var('http://example.com', FILTER_VALIDATE_URL)); // Returns: string(18) &quot;http://example.com&quot;

// Example usage
$email = 'email@example.com'; // or something submitted from a form.
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ // If this returns false
	die('The email you send is invalid.');
}
?&gt;</pre>
</p>
<p>A handful of the useful <a href="http://www.php.net/manual/en/filter.filters.php">available filters</a> are:</p>
<ul>
<li>FILTER_SANITIZE_STRING &#8211; Removes HTML tags and possibly unwanted characters.</li>
<li>FILTER_SANITIZE_EMAIL &#8211; Removes unwanted characters from an email address.</li>
<li>FILTER_SANITIZE_URL &#8211; Removes unwanted characters from a URL.</li>
<li>FILTER_SANITIZE_NUMBER_INT &#8211; Returns only digits,  + and -.</li>
<li>FILTER_VALIDATE_INT &#8211; If data is not an integer it will return false.</li>
<li>FILTER_VALIDATE_URL &#8211; If data is not a URL it will return false.</li>
<li>FILTER_VALIDATE_EMAIL &#8211; If data is not an email it will return false.</li>
<li>FILTER_VALIDATE_IP- If data is not an IP it will return false.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.fullondesign.co.uk/coding/php/1456-how-to-use-the-filter-functions-in-php.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>URL Shortening Function</title>
		<link>http://www.fullondesign.co.uk/coding/php/1319-url-shortening-function.htm</link>
		<comments>http://www.fullondesign.co.uk/coding/php/1319-url-shortening-function.htm#comments</comments>
		<pubDate>Fri, 08 Jan 2010 23:20:02 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.fullondesign.co.uk/?p=1319</guid>
		<description><![CDATA[Here is a function I use from time to time in my code which I thought I should share. It allows you to quickly shorten URL&#8217;s via 6 popular URL shortening websites. function shorten_url($url, $service=NULL){ if($service== 'tinyurl'){return get_link('http://tinyurl.com/api-create.php?url='.urlencode($url));} elseif($service == 'urly'){return get_link('http://ur.ly/new.txt?href='.urlencode($url));} elseif($service == 'isgd'){return get_link('http://is.gd/api.php?longurl='.urlencode($url));} elseif($service == 'klam'){return get_link('http://kl.am/api/shorten/?format=text&#38;url='.urlencode($url));} elseif($service == 'unu'){return get_link('http://u.nu/unu-api-simple?url='.urlencode($url));} else{return [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a function I use from time to time in my code which I thought I should share. It allows you to quickly shorten URL&#8217;s via 6 popular URL shortening websites.</p>
<pre class="brush: php;">
function shorten_url($url, $service=NULL){
		if($service== 'tinyurl'){return get_link('http://tinyurl.com/api-create.php?url='.urlencode($url));}
		elseif($service == 'urly'){return get_link('http://ur.ly/new.txt?href='.urlencode($url));}
		elseif($service == 'isgd'){return get_link('http://is.gd/api.php?longurl='.urlencode($url));}
		elseif($service == 'klam'){return get_link('http://kl.am/api/shorten/?format=text&amp;url='.urlencode($url));}
		elseif($service == 'unu'){return get_link('http://u.nu/unu-api-simple?url='.urlencode($url));}
		else{return get_link('http://api.tr.im/v1/trim_simple?url='.urlencode($url));}
		return $url;
	}

	function get_link($url){
		if(function_exists('curl_init')){
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_VERBOSE, 1);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			//curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
			//curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_URL, $url);
			$result = curl_exec($ch);
			$resultArray = curl_getinfo($ch);
			if ($resultArray['http_code'] == 200){
				return $result;
			} else {
				return FALSE;
			}
			curl_close($ch);
		}elseif(ini_get('allow_url_fopen') == 1){
			return fopen($url, 'r');
		}
		return FALSE;
	}

/* Usage */
echo shorten_url('http://www.fullondesign.co.uk/');
// returns: http://tr.im/JPCz
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fullondesign.co.uk/coding/php/1319-url-shortening-function.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Function: realpath()</title>
		<link>http://www.fullondesign.co.uk/coding/php/1297-php-function-realpath.htm</link>
		<comments>http://www.fullondesign.co.uk/coding/php/1297-php-function-realpath.htm#comments</comments>
		<pubDate>Sat, 19 Dec 2009 23:23:49 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Absolute Link]]></category>
		<category><![CDATA[Php Functions]]></category>
		<category><![CDATA[realpath]]></category>
		<category><![CDATA[Symbolic Link]]></category>

		<guid isPermaLink="false">http://www.fullondesign.co.uk/?p=1297</guid>
		<description><![CDATA[One functions I wish I had known about when i start learned PHP is the realpath() function. Pretty much what it does is take symbolic link (such as &#8216;../&#8217; or &#8216;/&#8217;) and returns a canonicalized absolute link (like &#8216;/home/public_html/folder&#8217;). Here is an example of it in action: &#60;?php echo realpath('../'); // Would return: /home/mike/www/blogposts ?&#62;]]></description>
			<content:encoded><![CDATA[<p>One functions I wish I had known about when i start learned PHP is the <a href="http://uk2.php.net/manual/en/function.realpath.php">realpath()</a> function. Pretty much what it does is take symbolic link (such as &#8216;../&#8217; or &#8216;/&#8217;) and returns a canonicalized absolute link (like &#8216;/home/public_html/folder&#8217;). Here is an example of it in action:</p>
<pre class="brush: php;">
&lt;?php
echo realpath('../');
// Would return: /home/mike/www/blogposts
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fullondesign.co.uk/coding/php/1297-php-function-realpath.htm/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Checking for embarrassing words in a string</title>
		<link>http://www.fullondesign.co.uk/coding/php/1069-checking-for-embarrassing-words-in-a-string.htm</link>
		<comments>http://www.fullondesign.co.uk/coding/php/1069-checking-for-embarrassing-words-in-a-string.htm#comments</comments>
		<pubDate>Tue, 16 Jun 2009 20:28:29 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[embarrassing words]]></category>
		<category><![CDATA[silly]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://www.fullondesign.co.uk/?p=1069</guid>
		<description><![CDATA[I was recently on YouTube and I noticed that did not check the shortened strings for potentially embarrassing shortenings of words. How to make a great example? Here is the code so you can shorten strings and check for potentially embrassing words. &#60;?php // String Cleaner - Cleans words you don't want out of strings. [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently on YouTube and I noticed that did not check the shortened strings for potentially embarrassing shortenings of words.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-1070" title="YouTube's Cock Up" src="http://www.fullondesign.co.uk/wp-content/uploads/2009/06/youtube-cock-up_small.png" alt="YouTube's Cock Up" width="439" height="263" /><em>How to make a great example?</em></p>
<p>Here is the code so you can shorten strings and check for potentially embrassing words.</p>
<p><span id="more-1069"></span></p>
<pre class="brush: php;">&lt;?php
// String Cleaner - Cleans words you don't want out of strings.

// Step 1 - Define the string and the words yoiu want to remove.
$string = 'this is my silly input how cool is it?';
$words_to_remove ='silly|my|eggs'; // Seperate words with | this is regular expression.

// Step 2 - shorten the string
$string = substr($string, 0, 23); // This with return the first 23 characters (including spaces) in the string.

// Step 3 - Remove the words
echo preg_replace('#\b('.$words_to_remove.')\b#is', '', $string); // This will remove the 

// This would return:
// this is input
?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fullondesign.co.uk/coding/php/1069-checking-for-embarrassing-words-in-a-string.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
