<?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>Ashley Ford - Tutorials :: jQuery :: PHP :: CSS :: HTML5 :: Papermashup.com</title>
	<atom:link href="http://papermashup.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://papermashup.com</link>
	<description>Ashley Ford - Tutorials :: jQuery :: PHP :: CSS :: HTML5 :: Papermashup.com</description>
	<lastBuildDate>Thu, 03 May 2012 13:39:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>WANTED: Web Developers</title>
		<link>http://papermashup.com/wanted-web-developers/</link>
		<comments>http://papermashup.com/wanted-web-developers/#comments</comments>
		<pubDate>Thu, 03 May 2012 13:39:45 +0000</pubDate>
		<dc:creator>Ashley</dc:creator>
				<category><![CDATA[Harkable]]></category>

		<guid isPermaLink="false">http://papermashup.com/?p=2567</guid>
		<description><![CDATA[My company Harkable.com is on the hunt for freelance web developers, preferably based in the UK but not essential. We&#8217;re mainly focused on PHP developers but we&#8217;re open to any skill set. Fill in our freelance form to get in &#8230; <br/> <a href="http://papermashup.com/wanted-web-developers/">Continue reading</a>]]></description>
			<content:encoded><![CDATA[<p>My company <a href="http://harkable.com">Harkable.com</a> is on the hunt for freelance web developers, preferably based in the UK but not essential. We&#8217;re mainly focused on PHP developers but we&#8217;re open to any skill set. Fill in our <a href="http://harkable.com/freelance-contact">freelance form</a> to get in touch.</p>
<h3>What do we do?</h3>
<p>Established in 2011, Harkable is a creative social technology company based in London, UK. </p>
<p>Harkable&#8217;s creative approach to social technology combines a passion for building innovative and exciting solutions to reach consumers, alongside a strategic and analytical method in everything we do.</p>
<p>The Harkable team has a unique knowledge of social media marketing and their expert, award-winning consultants have a broad range of experience working with a number of brands including Trinity Mirror, Myspace, Veuve Clicquot, Volkswagen, DDB, OMD &#038; Virgin. You can find out more about us <a href="http://harkable.com/about">here</a>.</p>
<h3>When do we need you?</h3>
<p>When can you start.. We&#8217;d ideally be looking for someone to start immediately.</p>
<p><a href="http://harkable.com/freelance-contact">Get in touch here</a> if you&#8217;re interested. We look forward to hearing from you.</p>
]]></content:encoded>
			<wfw:commentRss>http://papermashup.com/wanted-web-developers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>6 Useful PHP code snippets</title>
		<link>http://papermashup.com/6-useful-php-code-snippets/</link>
		<comments>http://papermashup.com/6-useful-php-code-snippets/#comments</comments>
		<pubDate>Mon, 06 Feb 2012 08:30:51 +0000</pubDate>
		<dc:creator>Ashley</dc:creator>
				<category><![CDATA[API's]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Tools]]></category>
		<category><![CDATA[APIs]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://papermashup.com/?p=2518</guid>
		<description><![CDATA[Here&#8217;s a selection of really useful PHP code snippets that I find using on a weekly basis. You could use these as is or expand them as part of other applications or add them to a php class. Adjust server &#8230; <br/> <a href="http://papermashup.com/6-useful-php-code-snippets/">Continue reading</a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a selection of really useful PHP code snippets that I find using on a weekly basis. You could use these as is or expand them as part of other applications or add them to a php class.<br/><br/></p>
<h3>Adjust server time</h3>
<p>If you have a server in a different timezone to you then you might be seeing funny things happen when you add the time to a MySQL database for example. You can fix this by adding or subtracting hours as in the example below.</p>
<pre class="brush: php; title: ;">

$now = date('Y-m-d-G');
$now = strftime(&quot;%Y-%m-%d-%H&quot;, strtotime(&quot;$now -8 hours&quot;));
</pre>
<h3>Create a slug URL from string of text</h3>
<p>Here we&#8217;re passing in a simple string of text converting it to lowercase and replacing all the spaces with a dash.</p>
<pre class="brush: php; title: ;">

function create_slug(strtolower($string)){
   $slug=preg_replace('/[^a-z0-9-]+/', '-', $string);
   return $slug;
}

echo create_slug('Create a slug URL from string of text');
</pre>
<h3>Convert HEX value to RBG</h3>
<p>If you&#8217;ve ever need to get an RGB colour format converted from a Hexadecimal this is the function for the job.</p>
<pre class="brush: php; title: ;">

function hextorgb($hexvalue){
        if($hexvalue[0] == '#') {
                $hexvalue = substr( $hexvalue, 1);
        }
        if(strlen( $hexvalue ) == 6){
                list($r, $g, $b) = array($hexvalue[0] . $hexvalue[1], $hexvalue[2] . $hexvalue[3], $hexvalue[4] . $hexvalue[5]);
        }elseif (strlen($hexvalue) == 3) {
                list($r,$g,$b) = array($hexvalue[0] . $hexvalue[0], $hexvalue[1] . $hexvalue[1], $hexvalue[2] . $hexvalue[2]);
        }else{
                return false;
        }
        $r = hexdec($r);
        $g = hexdec($g);
        $b = hexdec($b);
        return array('R' =&gt; $r, 'G' =&gt; $g, 'B' =&gt; $b);
}

$rgb = hextorgb('#fff000');

print_r($rgb);
</pre>
<h3>Display a users Gravatar image</h3>
<p>Getting users images from Gravatar is simple. If you have the users email address you just need to MD5 hash it and append it to the gravatar URL. </p>
<pre class="brush: php; title: ;">
   $gravatar = 'http://www.gravatar.com/avatar/' . md5($email_address) . '?s=32';
   echo '&lt;img src=&quot;' . $gravatar . '&quot; width=&quot;32&quot; height=&quot;32&quot;/&gt;';
</pre>
<h3>Convert links in a string of text to hyperlinks</h3>
<p>Very useful function which will convert a string of text and ad  hyperlinks to all the URLs. We loop through each URL and add a hyperlink</p>
<pre class="brush: php; title: ;">

function url_to_link($text){

            $reg_exUrl = &quot;/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/&quot;;
            // Check if there is a url in the string
            if (preg_match_all($reg_exUrl, $text, $url)) {

                foreach($url[0] as $v){

                    $position = strpos($text,' '.$v)+1;
                    $text = substr_replace($text,'', $position, strlen($v));
                    $text = substr_replace($text,''.$v.'', $position ,0);
                }
                return $text;
            }
            else {
                // if no urls in the text just return the text
                return $text;
            }
        }

$string = 'This is a string of text and we have a link: http://papermashup.com we also have another link http://google.com';
echo url_to_link($string);
</pre>
<h3>Parse JSON in PHP</h3>
<p>Parsing a string of JSON is easier than you may think as we can use the json_decode() function in PHP which will convert the JSON into an array in PHP which we can then manipulate as needed.</p>
<pre class="brush: php; title: ;">

  $json ='{&quot;id&quot;:0,&quot;name&quot;:&quot;Ashley&quot;,&quot;surname&quot;:&quot;Ford&quot;,&quot;Website&quot;:&quot;http://papermashup.com&quot;} ';

   $array=json_decode($json);

   // print  the array
   print_r($array);
   echo $array-&gt;name; 
</pre>
]]></content:encoded>
			<wfw:commentRss>http://papermashup.com/6-useful-php-code-snippets/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Create an error page to handle all errors with PHP</title>
		<link>http://papermashup.com/create-an-error-page-to-handle-all-errors-with-php/</link>
		<comments>http://papermashup.com/create-an-error-page-to-handle-all-errors-with-php/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 10:39:31 +0000</pubDate>
		<dc:creator>Ashley</dc:creator>
				<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://papermashup.com/?p=2535</guid>
		<description><![CDATA[Here&#8217;s a very simple solution to handling a variety of HTTP errors like 404, 500.. etc in one php file. All we need to do is create an array of error codes and match against them by picking up the &#8230; <br/> <a href="http://papermashup.com/create-an-error-page-to-handle-all-errors-with-php/">Continue reading</a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a very simple solution to handling a variety of HTTP errors like 404, 500.. etc in one php file. All we need to do is create an array of error codes and match against them by picking up the global redirect status code using PHP. This means that we can use one page the handle multiple errors.</p>
<h3>The Code</h3>
<p>You&#8217;ll need to update your .htaccess file so when an error is detected the server knows how to handle the request. In our case we&#8217;re going to forward all the listed errors to our generic errors.php file.</p>
<pre class="brush: xml; title: ;">

ErrorDocument 400 /errors.php
ErrorDocument 403 /errors.php
ErrorDocument 404 /errors.php
ErrorDocument 405 /errors.php
ErrorDocument 408 /errors.php
ErrorDocument 500 /errors.php
ErrorDocument 502 /errors.php
ErrorDocument 504 /errors.php
</pre>
<h3>The PHP</h3>
<p>This is the contents of the &#8216;errors.php&#8217; file. You need to save this in the root directory of your web server, unless you modify the path in the .htaccess file above.</p>
<pre class="brush: php; title: ;">

$status = $_SERVER['REDIRECT_STATUS'];
$codes = array(
       400 =&gt; array('400 Bad Request', 'The request cannot be fulfilled due to bad syntax.'),
       403 =&gt; array('403 Forbidden', 'The server has refused to fulfil your request.'),
       404 =&gt; array('404 Not Found', 'The page you requested was not found on this server.'),
       405 =&gt; array('405 Method Not Allowed', 'The method specified in the request is not allowed for the specified resource.'),
       408 =&gt; array('408 Request Timeout', 'Your browser failed to send a request in the time allowed by the server.'),
       500 =&gt; array('500 Internal Server Error', 'The request was unsuccessful due to an unexpected condition encountered by the server.'),
       502 =&gt; array('502 Bad Gateway', 'The server received an invalid response while trying to carry out the request.'),
       504 =&gt; array('504 Gateway Timeout', 'The upstream server failed to send a request in the time allowed by the server.'),
);

$title = $codes[$status][0];
$message = $codes[$status][1];
if ($title == false || strlen($status) != 3) {
       $message = 'Please supply a valid HTTP status code.';
}

echo '&lt;h1&gt;Hold up! '.$title.' detected&lt;/h1&gt;
&lt;p&gt;'.$message.'&lt;/p&gt;';
</pre>
]]></content:encoded>
			<wfw:commentRss>http://papermashup.com/create-an-error-page-to-handle-all-errors-with-php/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>PHP check if your website is up</title>
		<link>http://papermashup.com/php-check-if-your-website-is-up/</link>
		<comments>http://papermashup.com/php-check-if-your-website-is-up/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 08:30:45 +0000</pubDate>
		<dc:creator>Ashley</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Tools]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://papermashup.com/?p=2510</guid>
		<description><![CDATA[Here&#8217;s a basic but useful snippet to either check that a website is online or domain exist. It&#8217;s a very simple function that uses CURL to check the response from a given URL. if a response is received we can &#8230; <br/> <a href="http://papermashup.com/php-check-if-your-website-is-up/">Continue reading</a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a basic but useful snippet to either check that a website is online or domain exist. It&#8217;s a very simple function that uses CURL to check the response from a given URL. if a response is received we can assume that the site is up/online.</p>
<h3>The Code</h3>
<pre class="brush: php; title: ;">

       function isSiteAvailable($url)
       {
               //check, if a valid url is provided
               if(!filter_var($url, FILTER_VALIDATE_URL))
               {
                       return 'URL provided wasn\'t valid';
               }

               //make the connection with curl
               $cl = curl_init($url);
               curl_setopt($cl,CURLOPT_CONNECTTIMEOUT,10);
               curl_setopt($cl,CURLOPT_HEADER,true);
               curl_setopt($cl,CURLOPT_NOBODY,true);
               curl_setopt($cl,CURLOPT_RETURNTRANSFER,true);

               //get response
               $response = curl_exec($cl);

               curl_close($cl);

               if ($response) return 'Site seems to be up and running!';

               return 'Oops nothing found, the site is either offline or the domain doesn\'t exist';
       }

	// check if site exists / is up
	if($_GET['url']){

	   $response = isSiteAvailable($_GET['url']);
	   $message = '&lt;div class=&quot;response&quot;&gt;'.$response.'&lt;/div&gt;';
	}
</pre>
<h3>Display the response</h3>
<pre class="brush: php; title: ;">

&lt;?php echo $message;?&gt;

&lt;form action=&quot;&quot; method=&quot;get&quot;&gt;

Enter a URL below or click an example below:&lt;br/&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;?url=http://harkable.com&quot;&gt;harkable.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;?url=http://google.com&quot;&gt;google.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;?url=http://sfdhjsdkhfskjfhskjfh.om&quot;&gt;sfdhjsdkhfskjfhskjfh.om&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;input name=&quot;url&quot; type=&quot;text&quot; value=&quot;&lt;?php echo $_GET['url'];?&gt;&quot; /&gt;

&lt;/form&gt;
</pre>
<p><a href="http://papermashup.com/demos/check-if-website-is-up/"><img src="http://papermashup.com/wp-content/uploads/2009/01/demo.png" alt="" title="demo" class="alignnone size-full wp-image-23" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://papermashup.com/php-check-if-your-website-is-up/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Animate through a set of list items with jQuery</title>
		<link>http://papermashup.com/animate-through-a-set-of-list-items-with-jquery/</link>
		<comments>http://papermashup.com/animate-through-a-set-of-list-items-with-jquery/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 11:29:10 +0000</pubDate>
		<dc:creator>Ashley</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Learn]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://papermashup.com/?p=2499</guid>
		<description><![CDATA[Here&#8217;s an interesting code snippet I&#8217;ve found handy in past projects. Great for highlighting specific information within an application or web page. To start with lets have a brief explanation as to what we&#8217;re going to be doing. We have &#8230; <br/> <a href="http://papermashup.com/animate-through-a-set-of-list-items-with-jquery/">Continue reading</a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an interesting code snippet I&#8217;ve found handy in past projects. Great for highlighting specific information within an application or web page. To start with lets have a brief explanation as to what we&#8217;re going to be doing. We have a set of items in a list, and we want to iterate though the list increasing and decreasing the font size. Here&#8217;s how it&#8217;s done.</p>
<h3>The Code</h3>
<p>Firstly we setup three variables that are used in the function, notice that we&#8217;re chaining the variables instead of declaring &#8216;var&#8217; each time which is the optimal way of declaring multiple vars in jQuery. You can adjust the delay and animate values to suit your needs. We then loop through each list item using the eq(); method which allows us to select which list item to animate, you can see we&#8217;re passing the variable &#8216;i&#8217; to this method which is increased towards the bottom of the script. Within the loop we finally call the function again to start the process again.</p>
<pre class="brush: jscript; title: ;">

$(document).ready(function() {

         var i = 0,
         delay = 2000,
         animate = 400;
         function animateList(){
                 var imax = $(&quot;ul#list li&quot;).length -1;
                 $(&quot;ul#list li:eq(&quot; + i + &quot;)&quot;)
                         .animate({&quot;fontSize&quot; : &quot;80px&quot;}, animate)
                         .animate({&quot;fontSize&quot; : &quot;80px&quot;}, delay)
                         .animate({&quot;fontSize&quot; : &quot;30px&quot;}, animate, function(){

                                 (i == imax) ? i=0 : i++;
                                 animateList();
                         });

                 };

	   animateList();
});
</pre>
<h3>The HTML</h3>
<pre class="brush: xml; title: ;">

&lt;ul id=&quot;list&quot;&gt;
&lt;li&gt;Advertising&lt;/li&gt;
&lt;li&gt;Art&lt;/li&gt;
&lt;li&gt;Automotive&lt;/li&gt;
&lt;li&gt;Business&lt;/li&gt;
&lt;li&gt;Celebrity&lt;/li&gt;
&lt;/ul&gt; 
</pre>
<p><a href="http://papermashup.com/demos/jquery-list-animation/"><img src="http://papermashup.com/wp-content/uploads/2009/01/demo.png" alt="" title="demo" class="alignnone size-full wp-image-23" /></a><a href="http://papermashup.com/demos/jquery-list-animation/jquery-list-animation.zip"><img src="http://papermashup.com/wp-content/uploads/2009/01/download.png" alt="download" title="download" class="alignnone size-full wp-image-24" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://papermashup.com/animate-through-a-set-of-list-items-with-jquery/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery Fancy Switch</title>
		<link>http://papermashup.com/jquery-fancy-switch/</link>
		<comments>http://papermashup.com/jquery-fancy-switch/#comments</comments>
		<pubDate>Thu, 24 Nov 2011 23:24:39 +0000</pubDate>
		<dc:creator>Ashley</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Learn]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Downloads]]></category>

		<guid isPermaLink="false">http://papermashup.com/?p=2489</guid>
		<description><![CDATA[I wrote a post a while back on coding an iPhone style switch using jQuery. I&#8217;ve now put together a simple tutorial demonstrating how simple it is to build a switch that triggers two radio buttons in a field set. &#8230; <br/> <a href="http://papermashup.com/jquery-fancy-switch/">Continue reading</a>]]></description>
			<content:encoded><![CDATA[<p>I wrote a post a while back on coding an <a href="http://papermashup.com/jquery-iphone-style-ajax-switch/" target="_blank">iPhone style switch</a> using jQuery. I&#8217;ve now put together a simple tutorial demonstrating how simple it is to build a switch that triggers two radio buttons in a field set. It also degrades gracefully if JavaScript is disabled just displaying the two radio buttons with labels. This tutorial is aimed at users just stepping on the jQuery ladder, and hopefully this will demonstrate how simple some techniques are. The design of the switch was done by <a href="http://dribbble.com/shots/166165-Web-Elements" target="_blank">Shegy</a> and you can download the full set of switch designs as a PSD <a href="http://www.psdchest.com/2011/05/09/web-elements/" target="_blank">here</a></p>
<h3>The Code</h3>
<p>Lets run through line by line the JavaScript. The first three lines after the DOM ready function are setup incase the user has JavaScript disabled. So if enabled we display the switch background image and hide the radio buttons as well as indent the text on the labels.</p>
<p>We&#8217;ve then setup a &#8216;change()&#8217; function which means the function is executed each time the user selects either checkbox, we then check the value of the radio button thats been selected and adjust the background position of the sprite image.</p>
<p>Lastly for demo purposes im just displaying the status of the radio buttons in the div with the class &#8216;result&#8217;</p>
<pre class="brush: jscript; title: ;">

$(document).ready(function(){

	$('.switch').css('background', 'url(&quot;switch.png&quot;)');
	$('.on_off').css('display','none');
	$('.on, .off').css('text-indent','-10000px');

    $(&quot;input[name=on_off]&quot;).change(function() {
      var button = $(this).val();

		if(button == 'off'){ $('.switch').css('background-position', 'right'); }
		if(button == 'on'){ $('.switch').css('background-position', 'left'); }	 

		 $('.result span').html(button);
		 $('.result').fadeIn();

   });

});
</pre>
<h3>The HTML</h3>
<p>Here we have a simple form with the two radio buttons in a fieldset.</p>
<pre class="brush: xml; title: ;">

&lt;form action=&quot;&quot; method=&quot;get&quot;&gt;

&lt;fieldset class=&quot;switch&quot;&gt;
    &lt;label class=&quot;off&quot;&gt;Off&lt;input type=&quot;radio&quot; class=&quot;on_off&quot; name=&quot;on_off&quot; value=&quot;off&quot;/&gt;&lt;/label&gt;
    &lt;label class=&quot;on&quot;&gt;On&lt;input type=&quot;radio&quot; class=&quot;on_off&quot; name=&quot;on_off&quot; value=&quot;on&quot;/&gt;&lt;/label&gt;
&lt;/fieldset&gt;

&lt;input type=&quot;submit&quot; value=&quot;Submit&quot;/&gt;

&lt;/form&gt;

&lt;div class=&quot;result&quot;&gt;The button is: &lt;span&gt;on&lt;/span&gt;&lt;/div&gt;
</pre>
<h3>The CSS</h3>
<pre class="brush: css; title: ;">

#container{background:#ebebeb;}

.switch{
	border:none;
	background:left no-repeat;
	width:105px;
	height:46px;
	padding:0;
	margin:0;
}

.on, .off{
	width:50px;
	height:40px;
	display:inline-block;
	cursor:pointer;
}

.result{display:none;}
</pre>
<p><a href="http://papermashup.com/demos/jquery-switch/"><img src="http://papermashup.com/wp-content/uploads/2009/01/demo.png" alt="" title="demo" class="alignnone size-full wp-image-23" /></a><a href="http://papermashup.com/demos/jquery-switch/jquery-switch.zip"><img src="http://papermashup.com/wp-content/uploads/2009/01/download.png" alt="download" title="download" class="alignnone size-full wp-image-24" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://papermashup.com/jquery-fancy-switch/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Using Google&#8217;s Weather API</title>
		<link>http://papermashup.com/using-googles-weather-api/</link>
		<comments>http://papermashup.com/using-googles-weather-api/#comments</comments>
		<pubDate>Tue, 25 Oct 2011 16:46:58 +0000</pubDate>
		<dc:creator>Ashley</dc:creator>
				<category><![CDATA[API's]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Widgets]]></category>
		<category><![CDATA[APIs]]></category>
		<category><![CDATA[Google]]></category>

		<guid isPermaLink="false">http://papermashup.com/?p=2471</guid>
		<description><![CDATA[I thought it would be a nice little project to write a tutorial on how to build a basic but powerful weather application for either mobile devices or the desktop. The application takes a set of Google weather API feeds &#8230; <br/> <a href="http://papermashup.com/using-googles-weather-api/">Continue reading</a>]]></description>
			<content:encoded><![CDATA[<p>I thought it would be a nice little project to write a tutorial on how to build a basic but powerful weather application for either mobile devices or the desktop. The application takes a set of Google weather API feeds and makes some simple decisions based on the output. For example we can recommend the user takes an umbrella if rain or storms are forecast, or whether the temperature warrants the need for warm clothes. Basic but nonetheless useful information.</p>
<h3>The Logic Code</h3>
<p>Lets have a quick run through at what the project consists of. Firstly we use the simplexml_load_file() PHP function to get the xml data for the given location. We then check to see if the current weather condition is in the XML file. If it doesn&#8217;t exist then we can make the assumption that the API feed couldn&#8217;t determine the location, bear in mind this is very basic error checking and if the feed fails it will still return this error.</p>
<p>We now do some basic data checking to to see what extra data we can give the user. Firstly we check on line 14 to see if the current weather and forecast are different, if they are different we&#8217;ll display the forecast if not we show just the current weather.</p>
<p>Next on lines 21 and 28 we do a simple check to see if the temperature is higher or lower than 20 degrees and echo whether it&#8217;s likely to be hot or cold. </p>
<p>Finally on lines 35 we check to see if the current or future forecast contains any rain or storms so we can recommend the user takes an umbrella. This is done using some basic PHP regular expression.</p>
<pre class="brush: php; title: ;">
	// load the XML feeds for the Google Weather API
	$xml = simplexml_load_file('http://www.google.com/ig/api?weather='.urlencode($_GET['location']));
	$current = $xml-&gt;xpath(&quot;/xml_api_reply/weather/current_conditions&quot;);
	$forecast = $xml-&gt;xpath(&quot;/xml_api_reply/weather/forecast_conditions&quot;);

	// do a basic error check to see if we can get the current weather condition for the given location
	// if no return an error.
	if(!$current[0]-&gt;condition['data']){

		$error = 'Couldn\'t determine this location';

		}

	// is the current weather the same as the forecast? if not display the forecast
	if(strtolower($current[0]-&gt;condition['data'])!=strtolower($forecast[0]-&gt;condition['data'])){

	$outlook = 'but the forecast says '.strtolower($forecast[0]-&gt;condition['data']);	

		}

	// if the temp in degrees c is below 20 i.e. cold
	if($current[0]-&gt;temp_c['data']&lt;=20){

	$coat = 'If you\'re going outside i\'d wrap up warm.';	

		}	

	// if the temp in degrees c is over 21 i.e. Warm / Hot
	if($current[0]-&gt;temp_c['data']&gt;=21){

	$coat = 'You should be ok without warm clothes today.';	

		}		

	// check to see if there is rain or storms forecast
	if (preg_match(&quot;/\brain\b/i&quot;, $current[0]-&gt;condition['data']) ||
		preg_match(&quot;/\brain\b/i&quot;, $forecast[0]-&gt;condition['data']) ||
		preg_match(&quot;/\bstorm\b/i&quot;, $current[0]-&gt;condition['data']) ||
		preg_match(&quot;/\bstorm\b/i&quot;, $forecast[0]-&gt;condition['data'])
		){

		$umbrella = ' But &lt;u&gt;don\'t forget to take an umbrella&lt;/u&gt;!';
		}
</pre>
<h3>Displaying the data</h3>
<pre class="brush: php; title: ;">
&lt;form action=&quot;&quot; method=&quot;get&quot;&gt;
&lt;label for=&quot;location&quot;&gt;Location&lt;/label&gt;
&lt;input type=&quot;text&quot; class=&quot;location&quot; name=&quot;location&quot; value=&quot;&lt;?php echo $_GET['location'];?&gt;&quot;/&gt;
&lt;/form&gt; 

&lt;?php if(!empty($_GET['location'])){

	if($error){ echo '&lt;div class=&quot;errors&quot;&gt;'.$error.'&lt;/div&gt;'; }else{

?&gt;

&lt;div class=&quot;weather_app&quot;&gt;

&lt;h1&gt;Weather Summary for &lt;?php echo $_GET['location'];?&gt;&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;?php echo '&lt;img src=&quot;http://google.com'.$current[0]-&gt;icon['data'].'&quot;/&gt;'; ?&gt; The weather in &lt;?php echo $_GET['location'];?&gt; is &lt;strong&gt;&lt;?php echo strtolower($current[0]-&gt;condition['data']).' '. $outlook;?&gt;&lt;/strong&gt;. The temperature is currently &lt;strong&gt;&lt;?php echo $current[0]-&gt;temp_c['data']; ?&gt;&amp;deg;c (&lt;?php echo $current[0]-&gt;temp_f['data']; ?&gt;&amp;deg;f)&lt;/strong&gt;. &lt;?php echo $coat;?&gt; &lt;?php echo $umbrella;?&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;

&lt;?php } } ?&gt;
</pre>
<p><a href="http://papermashup.com/demos/google-weather-api/?location=Bristol"><img src="http://papermashup.com/wp-content/uploads/2009/01/demo.png" alt="" title="demo" class="alignnone size-full wp-image-23" /></a> <a href="http://papermashup.com/demos/google-weather-api/google-weather-api.zip"><img src="http://papermashup.com/wp-content/uploads/2009/01/download.png" alt="download" title="download" class="alignnone size-full wp-image-24" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://papermashup.com/using-googles-weather-api/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>jQuery Show / Hide Plugin</title>
		<link>http://papermashup.com/jquery-show-hide-plugin/</link>
		<comments>http://papermashup.com/jquery-show-hide-plugin/#comments</comments>
		<pubDate>Wed, 28 Sep 2011 17:28:06 +0000</pubDate>
		<dc:creator>Ashley</dc:creator>
				<category><![CDATA[Downloads]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[popular]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://papermashup.com/?p=2451</guid>
		<description><![CDATA[Due to popular demand here&#8217;s a re-written version of the tutorial I wrote over a year ago on how to show and hide content using jQuery. After I first published the post I&#8217;ve had a lot of requests as to &#8230; <br/> <a href="http://papermashup.com/jquery-show-hide-plugin/">Continue reading</a>]]></description>
			<content:encoded><![CDATA[<p>Due to popular demand here&#8217;s a re-written version of the tutorial I wrote over a year ago on how to show and hide content using jQuery. After I first published the post I&#8217;ve had a lot of requests as to how you can show and hide multiple divs so I&#8217;ve written this plugin which does all the work for you!</p>
<h3>The Plugin</h3>
<pre class="brush: jscript; title: ;">
(function ($) {
    $.fn.showHide = function (options) {

	//default vars for the plugin
        var defaults = {
            speed: 1000,
			easing: '',
			changeText: 0,
			showText: 'Show',
			hideText: 'Hide'

        };
        var options = $.extend(defaults, options);

        $(this).click(function () {
// optionally add the class .toggleDiv to each div you want to automatically close
                      $('.toggleDiv').slideUp(options.speed, options.easing);
			 // this var stores which button you've clicked
             var toggleClick = $(this);
		     // this reads the rel attribute of the button to determine which div id to toggle
		     var toggleDiv = $(this).attr('rel');
		     // here we toggle show/hide the correct div at the right speed and using which easing effect
		     $(toggleDiv).slideToggle(options.speed, options.easing, function() {
		     // this only fires once the animation is completed
			 if(options.changeText==1){
		     $(toggleDiv).is(&quot;:visible&quot;) ? toggleClick.text(options.hideText) : toggleClick.text(options.showText);
			 }
              });

		  return false;

        });

    };
})(jQuery);
</pre>
<h3>The Usage</h3>
<p>Here we setup the options for the plugin. you can set the speed of the toggle, if you include the jQuery UI plugin you can specify an easing effect. Also there&#8217;s an option to change the text for the button. 1 is change 0 is dont change. and the final options are the show and hide text.</p>
<pre class="brush: jscript; title: ;">

$(document).ready(function(){

   $('.show_hide').showHide({
		speed: 1000,  // speed you want the toggle to happen
		easing: '',  // the animation effect you want. Remove this line if you dont want an effect and if you haven't included jQuery UI
		changeText: 1, // if you dont want the button text to change, set this to 0
		showText: 'View',// the button text to show when a div is closed
		hideText: 'Close' // the button text to show when a div is open

	});

});
</pre>
<h3>The HTML</h3>
<p>Here you can see the simple usage for the plugin. We&#8217;ve already set the plugin options above in our DOM ready function now here we set our divs up. for element you want to toggle, you just need to add the div id to the rel attribute of the a tag as shown below. You can now add as many show hide divs as you want to.</p>
<blockquote><p>If you want all the open divs to close when you click to open another simply add the class .toggleDiv to each element.</p></blockquote>
<pre class="brush: xml; title: ;">
 &lt;a class=&quot;show_hide&quot; href=&quot;#&quot; rel=&quot;#slidingDiv&quot;&gt;View&lt;/a&gt;&lt;/pre&gt;
&lt;div id=&quot;slidingDiv&quot; class=&quot;toggleDiv&quot; style=&quot;display: none;&quot;&gt;Fill this space with really interesting content.&lt;/div&gt;
&lt;pre&gt;
 &lt;a class=&quot;show_hide&quot; href=&quot;#&quot; rel=&quot;#slidingDiv_2&quot;&gt;View&lt;/a&gt;&lt;/pre&gt;
&lt;div id=&quot;slidingDiv_2&quot; class=&quot;toggleDiv&quot; style=&quot;display: none;&quot;&gt;Fill this space with really interesting content.&lt;/div&gt;
&lt;pre&gt;
</pre>
<p><a href="http://papermashup.com/demos/jquery-show-hide-plugin/"><img class="alignnone size-full wp-image-23" title="demo" src="http://papermashup.com/wp-content/uploads/2009/01/demo.png" alt="" /></a> <a href="http://papermashup.com/demos/jquery-show-hide-plugin/jquery-show-hide-plugin.zip"><img class="alignnone size-full wp-image-24" title="download" src="http://papermashup.com/wp-content/uploads/2009/01/download.png" alt="download" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://papermashup.com/jquery-show-hide-plugin/feed/</wfw:commentRss>
		<slash:comments>113</slash:comments>
		</item>
		<item>
		<title>Country drop down list with php function</title>
		<link>http://papermashup.com/country-drop-down-list-with-php-function/</link>
		<comments>http://papermashup.com/country-drop-down-list-with-php-function/#comments</comments>
		<pubDate>Thu, 18 Aug 2011 06:30:21 +0000</pubDate>
		<dc:creator>Ashley</dc:creator>
				<category><![CDATA[API's]]></category>
		<category><![CDATA[Downloads]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://papermashup.com/?p=2429</guid>
		<description><![CDATA[I had a project recently that required the user to select their country from a drop down list and store the data in a database. It was such a long process setting up the PHP switch statement that I thought &#8230; <br/> <a href="http://papermashup.com/country-drop-down-list-with-php-function/">Continue reading</a>]]></description>
			<content:encoded><![CDATA[<p>I had a project recently that required the user to select their country from a drop down list and store the data in a database. It was such a long process setting up the PHP switch statement that I thought someone might find it useful for a project. The code below is a snapshot of the switch statement I&#8217;ve setup. The download at the bottom includes 238 countries and continents. You just need to store the country code in the database then call the function below to return the country name.</p>
<h3>Code snapshot</h3>
<p>Below is a snapshop of the PHP switch statement. <a href="http://papermashup.com/demos/php-country-dropdown/php-country-dropdown.zip">Download the full code of the tutorial here</a>. Upload the PHP file included and see the demos.</p>
<pre class="brush: php; title: ;">

function user_country($country){

	switch($country){

		case 'AF':
		$name = 'Afghanistan';
		break;

	        case 'AL':
		$name = 'Albania';
		break;	

	        case 'DZ':
		$name = 'Algeria';
		break....	

	  } 

	return array(

		&quot;name&quot; =&gt; $name

		);

		}
</pre>
<h3>The HTML</h3>
<p>Again this is a snapshot of the select drop down form.</p>
<pre class="brush: xml; title: ;">

    &lt;label&gt;Country&lt;/label&gt;
        &lt;select name=&quot;country&quot;&gt;
          &lt;option value=&quot;AF&quot;&gt;Afghanistan&lt;/option&gt;
          &lt;option value=&quot;AL&quot;&gt;Albania&lt;/option&gt;
          &lt;option value=&quot;DZ&quot;&gt;Algeria&lt;/option&gt;
    	  .......
        &lt;/select&gt; 
</pre>
<p><a href="http://papermashup.com/demos/php-country-dropdown/php-country-dropdown.zip"><img src="http://papermashup.com/wp-content/uploads/2009/01/download.png" alt="download" title="download" class="alignnone size-full wp-image-24" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://papermashup.com/country-drop-down-list-with-php-function/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Display breadcrumbs on your site using PHP</title>
		<link>http://papermashup.com/how-to-display-breadcrumbs-on-your-site-using-php/</link>
		<comments>http://papermashup.com/how-to-display-breadcrumbs-on-your-site-using-php/#comments</comments>
		<pubDate>Wed, 17 Aug 2011 06:30:09 +0000</pubDate>
		<dc:creator>Ashley</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Web Tools]]></category>
		<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://papermashup.com/?p=2411</guid>
		<description><![CDATA[When you have a fully dynamic site it&#8217;s useful to show the user where they are by breaking down the URL structure so they can navigate backwards through the site. For example this url: http://papermashup.com/categories/jquery/ shows that &#8216;jquery&#8217; is part &#8230; <br/> <a href="http://papermashup.com/how-to-display-breadcrumbs-on-your-site-using-php/">Continue reading</a>]]></description>
			<content:encoded><![CDATA[<p>When you have a fully dynamic site it&#8217;s useful to show the user where they are by breaking down the URL structure so they can navigate backwards through the site. For example this url: http://papermashup.com/categories/jquery/ shows that &#8216;jquery&#8217; is part of &#8216;categories&#8217; so the user could navigate backwards through the url structure.</p>
<h3>The Code</h3>
<p>The first line of the function gets the REQUEST_URI (/path/to/file.php), splits the string (using &#8216;/&#8217;) into an array, then filters out any empty values. We then store the base url for the site in $base_url. Next we find the array key for the last value in the $path array. We then do a for loop to build up the breadcrumbs and determine where to put the a tag etc.</p>
<pre class="brush: php; title: ;">

function breadcrumbs($separator = ' &amp;raquo; ', $home = 'Home') {

    $path = array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)));
    $base_url = ($_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/';
    $breadcrumbs = array(&quot;&lt;a href=\&quot;$base_url\&quot;&gt;$home&lt;/a&gt;&quot;);

    $last = end(array_keys($path));

    foreach ($path AS $x =&gt; $crumb) {
        $title = ucwords(str_replace(array('.php', '_'), Array('', ' '), $crumb));
        if ($x != $last){
            $breadcrumbs[] = '&lt;a href=&quot;$base_url$crumb&quot;&gt;$title&lt;/a&gt;';
        }else{
            $breadcrumbs[] = $title;
		}
    }

    return implode($separator, $breadcrumbs);
}	
</pre>
<h3>Calling the function</h3>
<p>This is the simple bit! Simply add the above function to the top of your PHP page and call the function as shown below. You can optionally add a separator symbol or specify the wording for &#8216;Home&#8217;.</p>
<pre class="brush: php; title: ;">

echo breadcrumbs();
</pre>
]]></content:encoded>
			<wfw:commentRss>http://papermashup.com/how-to-display-breadcrumbs-on-your-site-using-php/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching using disk: basic
Object Caching 816/923 objects using disk: basic

Served from: papermashup.com @ 2012-05-17 06:03:19 -->
