<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Ashley Ford - Tutorials :: jQuery :: PHP :: CSS :: HTML5 :: Papermashup.com</title><link>http://papermashup.com</link><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/AshleyFord-Papermashupcom" /><description>Ashley Ford - Tutorials :: jQuery :: PHP :: CSS :: HTML5 :: Papermashup.com</description><language>en</language><lastBuildDate>Mon, 21 May 2012 00:30:24 PDT</lastBuildDate><generator>WordPress http://wordpress.org/</generator><feedburner:info uri="ashleyford-papermashupcom" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><geo:lat>51.621490</geo:lat><geo:long>-0.096489</geo:long><creativeCommons:license>http://creativecommons.org/licenses/by-sa/2.0/</creativeCommons:license><feedburner:emailServiceId>AshleyFord-Papermashupcom</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item><title>jQuery dynamic number ticker</title><link>http://feedproxy.google.com/~r/AshleyFord-Papermashupcom/~3/Jj6Ifc_LkvM/</link><category>Downloads</category><category>Javascript</category><category>jQuery</category><category>JSON</category><category>MySQL</category><category>PHP</category><category>Tutorials</category><category>Regular Expression</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ashley</dc:creator><pubDate>Sun, 20 May 2012 11:56:23 PDT</pubDate><guid isPermaLink="false">http://papermashup.com/?p=2617</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>This is a fascinating little script that helps you display a dynamic JSON feed of numbers that automatically updates on the page by animating up or down to the current number. A great addition as part of a realtime analytical dashboard.<br/><br/></p>
<h3>The JS Code</h3>
<p>There are three functions in total. The first one &#8216;format_number&#8217; which works the same as number_format(); in PHP adding the decimal places. the &#8216;magic_number&#8217; function then takes the current number and the new number and animates between them.</p>
<p>Finally we have the &#8216;update&#8217; function which retrieves the new data set of numbers (randomly generated in PHP for the demo) via a JSONP feed. At the bottom of the script we&#8217;re refreshing the data every 4 seconds. Oh and dont forget to include the jQuery library.</p>
<pre class="brush: jscript; title: ;">

  counts = {};

        function format_number(text){
            return text.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, &quot;$1,&quot;);
        };

        function magic_number(element_name, value) {
            var elem = $(element_name);
            var current = counts[element_name] || 0;
            $({count: current}).animate({count: value}, {
                                        duration: 500,
                                        step: function() {
                                            elem.text(format_number(String(parseInt(this.count))));
                                        }});
            							counts[element_name] = value;
        };

        function update() {
            var jqxhr = $.getJSON(&quot;number.php?jsonp=?&quot;, function(data) {

                                magic_number(&quot;#number1&quot;, data[0]['n1']);
								magic_number(&quot;#number2&quot;, data[0]['n2']);
                       });
        };

        setInterval(update, 4000);
        update();
</pre>
<h3>The PHP</h3>
<p>For the example number.php generates random numbers and returns them as a JSON object. You could easily add as many numbers to the feed as you like, even retrieving data from a database, simply add extra values to the array below as shown commented out.</p>
<pre class="brush: jscript; title: ;">

	$total_data = array(
		array(
			'total' =&gt; rand(0,99999999),
			'twitter' =&gt; rand(0,99999999)
                   // , 'dummy-entry' =&gt; $var
		 ),
	);
	echo $_GET['jsonp'].'('. json_encode($total_data) . ')';
</pre>
<p><a href="http://papermashup.com/demos/jquery-number-scroller/"><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-number-scroller/jquery-number-scroller.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>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?a=Jj6Ifc_LkvM:2x-s1XY3Yac:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?a=Jj6Ifc_LkvM:2x-s1XY3Yac:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AshleyFord-Papermashupcom/~4/Jj6Ifc_LkvM" height="1" width="1"/>]]></content:encoded><description>This is a fascinating little script that helps you display a dynamic JSON feed of numbers that automatically updates on the page by animating up or down to the current number. A great addition as part of a realtime analytical &amp;#8230; &lt;br/&gt; &lt;a href="http://papermashup.com/jquery-dynamic-number-ticker/"&gt;Continue reading&lt;/a&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://papermashup.com/jquery-dynamic-number-ticker/</feedburner:origLink></item><item><title>10 Free scripts to download</title><link>http://feedproxy.google.com/~r/AshleyFord-Papermashupcom/~3/94beyD8eSQU/</link><category>API's</category><category>Bundles</category><category>CSS</category><category>HTML5</category><category>Javascript</category><category>jQuery</category><category>Learn</category><category>MySQL</category><category>PHP</category><category>popular</category><category>Tutorials</category><category>APIs</category><category>Downloads</category><category>tools</category><category>Web</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ashley</dc:creator><pubDate>Sat, 19 May 2012 02:14:10 PDT</pubDate><guid isPermaLink="false">http://papermashup.com/?p=2584</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>It&#8217;s been a while since I put together the &#8220;<em><a href="http://papermashup.com/20-complete-scripts-to-download/" title="20 Complete scripts to download">20 Complete scripts to download</a></em>&#8221; post so I thought it was time for a quick roundup of some of the best downloads I&#8217;ve put together on Papermashup. You can download each file individually if you wish or click the big blue download button at the bottom of the post to get the complete bundle.</p>
<h3>1. Building an animated 3D poll</h3>
<p><img src="http://papermashup.com/wp-content/uploads/2012/05/poll.png" style="padding:0; border:0;" title="Poll Download" width="713" height="137" class="alignnone size-full wp-image-2591" /><br />
<a href="http://papermashup.com/demos/3d-poll/">Demo</a> <a href="http://papermashup.com/demos/3d-poll/3d-poll.zip">Download</a></p>
<h3>2. jQuery Face Detection</h3>
<p><img src="http://papermashup.com/wp-content/uploads/2012/05/face.png" style="padding:0; border:0;" title="Face Detection" width="713" height="137" class="alignnone size-full wp-image-2591" /><br />
<a href="http://papermashup.com/demos/jquery-facedetect/">Demo</a> <a href="https://github.com/jaysalvat/jquery.facedetection">Download</a></p>
<h3>3. HTML5 Geo location using the Google API</h3>
<p><img src="http://papermashup.com/wp-content/uploads/2012/05/map.png" style="padding:0; border:0;" title="Geo Location" width="713" height="137" class="alignnone size-full wp-image-2591" /><br />
<a href="http://papermashup.com/demos/html5-geolocation/">Demo</a> <a href="http://papermashup.com/demos/html5-geolocation/html5-geolocation.zip">Download</a></p>
<h3>4. Automatic jQuery site subscription lightbox</h3>
<p><img src="http://papermashup.com/wp-content/uploads/2012/05/subscribe.png" style="padding:0; border:0;" title="Geo Location" width="713" height="137" class="alignnone size-full wp-image-2591" /><br />
<a href="http://papermashup.com/demos/jquery-subscription-box/">Demo</a> <a href="http://papermashup.com/demos/jquery-subscription-box/jquery-subscription-box.zip">Download</a></p>
<h3>5. jQuery UI Slider</h3>
<p><img src="http://papermashup.com/wp-content/uploads/2012/05/slider.png" style="padding:0; border:0;" title="Geo Location" width="713" height="137" class="alignnone size-full wp-image-2591" /><br />
<a href="http://papermashup.com/demos/jquery-slider-bar/">Demo</a> <a href="http://papermashup.com/demos/jquery-slider-bar/jquery-slider-bar.zip">Download</a></p>
<h3>6. jQuery Fancy Switch</h3>
<p><img src="http://papermashup.com/wp-content/uploads/2012/05/switch.png" style="padding:0; border:0;" title="Geo Location" width="713" height="137" class="alignnone size-full wp-image-2591" /><br />
<a href="http://papermashup.com/demos/jquery-switch/">Demo</a> <a href="http://papermashup.com/demos/jquery-switch/jquery-switch.zip">Download</a></p>
<h3>7. jQuery Show / Hide Plugin</h3>
<p><img src="http://papermashup.com/wp-content/uploads/2012/05/showhide.png" style="padding:0; border:0;" title="Geo Location" width="713" height="137" class="alignnone size-full wp-image-2591" /><br />
<a href="http://papermashup.com/demos/jquery-show-hide-plugin/">Demo</a> <a href="http://papermashup.com/demos/jquery-show-hide-plugin/jquery-show-hide-plugin.zip">Download</a></p>
<h3>8. Using Google&#8217;s Weather API</h3>
<p><img src="http://papermashup.com/wp-content/uploads/2012/05/weather.png" style="padding:0; border:0;" title="Geo Location" width="713" height="137" class="alignnone size-full wp-image-2591" /><br />
<a href="http://papermashup.com/demos/google-weather-api/?location=Bristol">Demo</a> <a href="http://papermashup.com/demos/google-weather-api/google-weather-api.zip">Download</a></p>
<h3>9. Build a jQuery content feature like MailChimp</h3>
<p><img src="http://papermashup.com/wp-content/uploads/2012/05/mailchimp.png" style="padding:0; border:0;" title="Geo Location" width="713" height="137" class="alignnone size-full wp-image-2591" /><br />
<a href="http://papermashup.com/demos/jquery-slideshow/">Demo</a> <a href="http://papermashup.com/demos/jquery-slideshow/jquery-slideshow.zip">Download</a></p>
<h3>10. Build a jQuery Plugin</h3>
<p><img src="http://papermashup.com/wp-content/uploads/2012/05/jquery.png" style="padding:0; border:0;" title="Geo Location" width="713" height="137" class="alignnone size-full wp-image-2591" /><br />
<a href="http://papermashup.com/demos/jquery-plugin/">Demo</a> <a href="http://papermashup.com/demos/jquery-plugin/jquery-plugin.zip">Download</a></p>
<p><a href="http://papermashup.com/demos/bundle/script-download.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>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?a=94beyD8eSQU:hDZ_bGZO3WQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?a=94beyD8eSQU:hDZ_bGZO3WQ:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AshleyFord-Papermashupcom/~4/94beyD8eSQU" height="1" width="1"/>]]></content:encoded><description>It&amp;#8217;s been a while since I put together the &amp;#8220;20 Complete scripts to download&amp;#8221; post so I thought it was time for a quick roundup of some of the best downloads I&amp;#8217;ve put together on Papermashup. You can download each &amp;#8230; &lt;br/&gt; &lt;a href="http://papermashup.com/10-free-scripts-to-download/"&gt;Continue reading&lt;/a&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://papermashup.com/10-free-scripts-to-download/</feedburner:origLink></item><item><title>Automatic jQuery site subscription lightbox</title><link>http://feedproxy.google.com/~r/AshleyFord-Papermashupcom/~3/cgdeDjSz45Q/</link><category>Javascript</category><category>jQuery</category><category>popular</category><category>CSS</category><category>Design</category><category>Downloads</category><category>rss</category><category>Subscription Box</category><category>Tutorials</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ashley</dc:creator><pubDate>Thu, 17 May 2012 12:51:45 PDT</pubDate><guid isPermaLink="false">http://papermashup.com/?p=2571</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>I&#8217;ve had many of you email me asking for a tutorial that shows how to create the subscription lightbox that activates for the first time you visit the site, and I&#8217;ve finally got around to writing it up.</p>
<h3>Getting Started</h3>
<p>You&#8217;ll need to include the jQuery library as well as the <a href="http://www.jacklmoore.com/colorbox" title="Colorbox" target="_blank">Colorbox</a> lightbox JS and CSS which are included in the download below.</p>
<pre class="brush: xml; title: ;">

&lt;!-- Color Box CSS --&gt;
&lt;link media=&quot;screen&quot; rel=&quot;stylesheet&quot; target=&quot;_blank&quot; href=&quot;css/colorbox.css&quot; /&gt;
&lt;!-- Style For the Subscription Box --&gt;
&lt;link media=&quot;screen&quot; rel=&quot;stylesheet&quot; target=&quot;_blank&quot; href=&quot;css/popup.css&quot; /&gt;
&lt;script language=&quot;javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script language=&quot;javascript&quot; src=&quot;js/colorbox.js&quot;&gt;&lt;/script&gt;
</pre>
<h3>The JS Code</h3>
<p>Once the page loads we check to see if the cookie exists and hasn&#8217;t expired. If it&#8217;s expired or doesn&#8217;t exist we set the cookie to expire in 15 days, and we show the lightbox.</p>
<pre class="brush: jscript; title: ;">

$(&quot;document&quot;).ready(function (){ 

       // load the overlay

        if (document.cookie.indexOf('visited=true') == -1) {
			var fifteenDays = 1000*60*60*24*15;
			var expires = new Date((new Date()).valueOf() + fifteenDays);
			document.cookie = &quot;visited=true;expires=&quot; + expires.toUTCString();
			$.colorbox({width:&quot;580px&quot;, inline:true, href:&quot;#subscribe_popup&quot;});
		}

		$(&quot;.open_popup&quot;).colorbox({width:&quot;580px&quot;, inline:true, href:&quot;#subscribe_popup&quot;});

 });
</pre>
<h3>The HTML</h3>
<p>Here&#8217;s the HTML for the lightbox. This can go anywhere on your page, although i&#8217;d recommend putting it just above the last body tag. There shouldn&#8217;t be any surprises here!</p>
<pre class="brush: xml; title: ;">

&lt;a href=&quot;#&quot; class=&quot;open_popup&quot;&gt;Click here to open the popup&lt;/a&gt;

&lt;!-- This contains the hidden content for inline calls for the subscribe box --&gt;
&lt;div style='display:none'&gt;
  &lt;div id='subscribe_popup' style='padding:10px;'&gt;
    &lt;h2 class=&quot;box-title&quot;&gt;Never miss an update from Papermashup&lt;/h2&gt;
    &lt;h3 class=&quot;box-tagline&quot;&gt;Get notified about the latest tutorials and downloads.&lt;/h3&gt;
    &lt;!-- BEGIN #subs-container --&gt;
    &lt;div id=&quot;subs-container&quot; class=&quot;clearfix&quot;&gt;
      &lt;!-- BEGIN .box-side --&gt;
      &lt;div class=&quot;box-side left&quot;&gt;
        &lt;div class=&quot;box-icon&quot;&gt;&lt;a class=&quot;email&quot; target=&quot;_blank&quot; href=&quot;http://feedburner.google.com/fb/a/mailverify?uri=AshleyFord-Papermashupcom&amp;loc=en_US&quot;&gt;&lt;img src=&quot;images/email.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
        &lt;h4&gt;&lt;a target=&quot;_blank&quot; href=&quot;http://feedburner.google.com/fb/a/mailverify?uri=AshleyFord-Papermashupcom&amp;loc=en_US&quot;&gt;Subscribe by Email&lt;/a&gt;&lt;/h4&gt;
        &lt;h5&gt;Get alerts directly into your inbox after each post and stay updated.&lt;/h5&gt;
        &lt;a class=&quot;sub&quot; target=&quot;_blank&quot; href=&quot;http://feedburner.google.com/fb/a/mailverify?uri=AshleyFord-Papermashupcom&amp;loc=en_US&quot; title=&quot;Subscribe Now!&quot;&gt;Subscribe&lt;/a&gt;
        &lt;!-- END .box-side --&gt;
      &lt;/div&gt;
      &lt;div id=&quot;box-or&quot;&gt;OR&lt;/div&gt;
      &lt;!-- BEGIN .box-right --&gt;
      &lt;div class=&quot;box-side right&quot;&gt;
        &lt;div class=&quot;box-icon&quot;&gt;&lt;a class=&quot;rss&quot; target=&quot;_blank&quot; href=&quot;http://feeds2.feedburner.com/AshleyFord-Papermashupcom&quot;&gt;&lt;img src=&quot;images/rss.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
        &lt;h4&gt;&lt;a target=&quot;_blank&quot; href=&quot;http://feeds2.feedburner.com/AshleyFord-Papermashupcom&quot;&gt;Subscribe by RSS&lt;/a&gt;&lt;/h4&gt;
        &lt;h5&gt;Add our RSS to your feedreader to get regular updates from us.&lt;/h5&gt;
        &lt;a class=&quot;sub&quot; target=&quot;_blank&quot; href=&quot;http://feeds2.feedburner.com/AshleyFord-Papermashupcom&quot; title=&quot;Subscribe Now!&quot;&gt;Subscribe&lt;/a&gt;
        &lt;!-- END .box-side --&gt;
      &lt;/div&gt;
      &lt;!-- BEGIN #subs-container --&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;!-- END subscribe popup--&gt;
</pre>
<p><a href="http://papermashup.com/demos/jquery-subscription-box/"><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-subscription-box/jquery-subscription-box.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>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?a=cgdeDjSz45Q:4n6ZKR1A7NU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?a=cgdeDjSz45Q:4n6ZKR1A7NU:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AshleyFord-Papermashupcom/~4/cgdeDjSz45Q" height="1" width="1"/>]]></content:encoded><description>I&amp;#8217;ve had many of you email me asking for a tutorial that shows how to create the subscription lightbox that activates for the first time you visit the site, and I&amp;#8217;ve finally got around to writing it up. Getting Started &amp;#8230; &lt;br/&gt; &lt;a href="http://papermashup.com/automatic-jquery-site-subscription-lightbox/"&gt;Continue reading&lt;/a&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://papermashup.com/automatic-jquery-site-subscription-lightbox/</feedburner:origLink></item><item><title>WANTED: Web Developers</title><link>http://feedproxy.google.com/~r/AshleyFord-Papermashupcom/~3/Zkk1Hjug3PM/</link><category>Harkable</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ashley</dc:creator><pubDate>Thu, 03 May 2012 06:39:45 PDT</pubDate><guid isPermaLink="false">http://papermashup.com/?p=2567</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![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>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?a=Zkk1Hjug3PM:e44XN0x3m60:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?a=Zkk1Hjug3PM:e44XN0x3m60:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AshleyFord-Papermashupcom/~4/Zkk1Hjug3PM" height="1" width="1"/>]]></content:encoded><description>My company Harkable.com is on the hunt for freelance web developers, preferably based in the UK but not essential. We&amp;#8217;re mainly focused on PHP developers but we&amp;#8217;re open to any skill set. Fill in our freelance form to get in &amp;#8230; &lt;br/&gt; &lt;a href="http://papermashup.com/wanted-web-developers/"&gt;Continue reading&lt;/a&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://papermashup.com/wanted-web-developers/</feedburner:origLink></item><item><title>6 Useful PHP code snippets</title><link>http://feedproxy.google.com/~r/AshleyFord-Papermashupcom/~3/R8eGKF7i6tk/</link><category>API's</category><category>JSON</category><category>PHP</category><category>Tutorials</category><category>Web Tools</category><category>APIs</category><category>Web</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ashley</dc:creator><pubDate>Fri, 27 Jan 2012 10:15:15 PST</pubDate><guid isPermaLink="false">http://papermashup.com/?p=2518</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![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>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?a=R8eGKF7i6tk:v5pKpNniaeg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?a=R8eGKF7i6tk:v5pKpNniaeg:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AshleyFord-Papermashupcom/~4/R8eGKF7i6tk" height="1" width="1"/>]]></content:encoded><description>Here&amp;#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 &amp;#8230; &lt;br/&gt; &lt;a href="http://papermashup.com/6-useful-php-code-snippets/"&gt;Continue reading&lt;/a&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total><feedburner:origLink>http://papermashup.com/6-useful-php-code-snippets/</feedburner:origLink></item><item><title>Create an error page to handle all errors with PHP</title><link>http://feedproxy.google.com/~r/AshleyFord-Papermashupcom/~3/evH3hW4FFTM/</link><category>.htaccess</category><category>PHP</category><category>Tutorials</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ashley</dc:creator><pubDate>Tue, 31 Jan 2012 03:22:12 PST</pubDate><guid isPermaLink="false">http://papermashup.com/?p=2535</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![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>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?a=evH3hW4FFTM:NE1CrvwZkMQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?a=evH3hW4FFTM:NE1CrvwZkMQ:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AshleyFord-Papermashupcom/~4/evH3hW4FFTM" height="1" width="1"/>]]></content:encoded><description>Here&amp;#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 &amp;#8230; &lt;br/&gt; &lt;a href="http://papermashup.com/create-an-error-page-to-handle-all-errors-with-php/"&gt;Continue reading&lt;/a&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">6</thr:total><feedburner:origLink>http://papermashup.com/create-an-error-page-to-handle-all-errors-with-php/</feedburner:origLink></item><item><title>PHP check if your website is up</title><link>http://feedproxy.google.com/~r/AshleyFord-Papermashupcom/~3/7Sni_zp78_8/</link><category>PHP</category><category>Tutorials</category><category>Web Tools</category><category>Web</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ashley</dc:creator><pubDate>Fri, 27 Jan 2012 08:39:10 PST</pubDate><guid isPermaLink="false">http://papermashup.com/?p=2510</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![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>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?a=7Sni_zp78_8:FfQxj_mFb1E:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?a=7Sni_zp78_8:FfQxj_mFb1E:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AshleyFord-Papermashupcom/~4/7Sni_zp78_8" height="1" width="1"/>]]></content:encoded><description>Here&amp;#8217;s a basic but useful snippet to either check that a website is online or domain exist. It&amp;#8217;s a very simple function that uses CURL to check the response from a given URL. if a response is received we can &amp;#8230; &lt;br/&gt; &lt;a href="http://papermashup.com/php-check-if-your-website-is-up/"&gt;Continue reading&lt;/a&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total><feedburner:origLink>http://papermashup.com/php-check-if-your-website-is-up/</feedburner:origLink></item><item><title>Animate through a set of list items with jQuery</title><link>http://feedproxy.google.com/~r/AshleyFord-Papermashupcom/~3/_ty8TJoEhLE/</link><category>Javascript</category><category>jQuery</category><category>Learn</category><category>Tutorials</category><category>Web</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ashley</dc:creator><pubDate>Fri, 27 Jan 2012 03:29:10 PST</pubDate><guid isPermaLink="false">http://papermashup.com/?p=2499</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![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>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?a=_ty8TJoEhLE:aAN282-HpH4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?a=_ty8TJoEhLE:aAN282-HpH4:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AshleyFord-Papermashupcom/~4/_ty8TJoEhLE" height="1" width="1"/>]]></content:encoded><description>Here&amp;#8217;s an interesting code snippet I&amp;#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&amp;#8217;re going to be doing. We have &amp;#8230; &lt;br/&gt; &lt;a href="http://papermashup.com/animate-through-a-set-of-list-items-with-jquery/"&gt;Continue reading&lt;/a&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://papermashup.com/animate-through-a-set-of-list-items-with-jquery/</feedburner:origLink></item><item><title>jQuery Fancy Switch</title><link>http://feedproxy.google.com/~r/AshleyFord-Papermashupcom/~3/1ttoHu4syBY/</link><category>Design</category><category>Javascript</category><category>jQuery</category><category>Learn</category><category>Tutorials</category><category>CSS</category><category>Downloads</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ashley</dc:creator><pubDate>Thu, 24 Nov 2011 15:24:39 PST</pubDate><guid isPermaLink="false">http://papermashup.com/?p=2489</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![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>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?a=1ttoHu4syBY:FAUBP0SCqf8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?a=1ttoHu4syBY:FAUBP0SCqf8:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AshleyFord-Papermashupcom/~4/1ttoHu4syBY" height="1" width="1"/>]]></content:encoded><description>I wrote a post a while back on coding an iPhone style switch using jQuery. I&amp;#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. &amp;#8230; &lt;br/&gt; &lt;a href="http://papermashup.com/jquery-fancy-switch/"&gt;Continue reading&lt;/a&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">16</thr:total><feedburner:origLink>http://papermashup.com/jquery-fancy-switch/</feedburner:origLink></item><item><title>Using Google’s Weather API</title><link>http://feedproxy.google.com/~r/AshleyFord-Papermashupcom/~3/2znJsulFXRY/</link><category>API's</category><category>Mobile</category><category>PHP</category><category>Tutorials</category><category>Widgets</category><category>APIs</category><category>Google</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ashley</dc:creator><pubDate>Tue, 25 Oct 2011 09:46:58 PDT</pubDate><guid isPermaLink="false">http://papermashup.com/?p=2471</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![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>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?a=2znJsulFXRY:466UcPEtLqs:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?a=2znJsulFXRY:466UcPEtLqs:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AshleyFord-Papermashupcom?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AshleyFord-Papermashupcom/~4/2znJsulFXRY" height="1" width="1"/>]]></content:encoded><description>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 &amp;#8230; &lt;br/&gt; &lt;a href="http://papermashup.com/using-googles-weather-api/"&gt;Continue reading&lt;/a&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">21</thr:total><feedburner:origLink>http://papermashup.com/using-googles-weather-api/</feedburner:origLink></item></channel></rss>

