<?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>Blog &#187; Matt</title>
	<atom:link href="http://blog.builtbyprime.com/author/matt/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.builtbyprime.com</link>
	<description>Prime Studios</description>
	<lastBuildDate>Tue, 20 Dec 2011 00:02:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>A Quick Weather API with PHP</title>
		<link>http://blog.builtbyprime.com/php/a-quick-weather-api-with-php</link>
		<comments>http://blog.builtbyprime.com/php/a-quick-weather-api-with-php#comments</comments>
		<pubDate>Fri, 26 Aug 2011 16:45:07 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.builtbyprime.com/?p=1800</guid>
		<description><![CDATA[I wanted to add a small weather status to the top of a web application, just to remind me what was going on in that city. This is some really simple code, based off of WunderGround&#8217;s API, using a city &#8230; <a href="http://blog.builtbyprime.com/php/a-quick-weather-api-with-php">Read more...</a>]]></description>
			<content:encoded><![CDATA[<p>I wanted to add a small weather status to the top of a web application, just to remind me what was going on in that city. This is some really simple code, based off of <a href="http://wiki.wunderground.com/index.php/API_-_XML">WunderGround&#8217;s API</a>, using a city airport&#8217;s conditions. Not going into much detail on this, or offering a completely robust solution, but here is the code I have in place.</p>
<p><img src="http://blog.builtbyprime.com/wp-content/uploads/california_app.png" alt="" title="california_app" width="650" height="117" class="alignleft size-full wp-image-1804" /></p>
<pre class="brush: php; title: ;">
  $url = 'http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=KSFO';
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  $data = curl_exec($ch);
  curl_close($ch);

  $xml = simplexml_load_string($data);

  $weather = $xml-&gt;weather;
  $temp = $xml-&gt;temp_f;
  $icon = $xml-&gt;icons-&gt;icon_set[9]-&gt;icon_url;
</pre>
<p>From this, you can set the three parsed variables into your html, and you are all set.</p>
<pre class="brush: xml; title: ;">
&lt;img src=&quot;&lt;?= $icon ?&gt;&quot;/&gt;
&lt;h3 style=&quot;margin-bottom:30px;&quot;&gt;It's currently &lt;?= $temp ?&gt;&amp;deg; and &lt;?= $weather ?&gt; in California.&lt;/h3&gt;
</pre>
<p>I am finding the call to take about 0.20s, which is acceptable to keep it all in PHP right now. Hope this helps in your quest.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.builtbyprime.com/php/a-quick-weather-api-with-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why I love the Nexus S (vs. iPhone 4)</title>
		<link>http://blog.builtbyprime.com/web/why-i-love-the-nexus-s-vs-iphone-4</link>
		<comments>http://blog.builtbyprime.com/web/why-i-love-the-nexus-s-vs-iphone-4#comments</comments>
		<pubDate>Sat, 07 May 2011 19:31:44 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://blog.builtbyprime.com/?p=1721</guid>
		<description><![CDATA[Google&#8217;s Nexus S (mfg. by Samsung) will officially come out for Sprint on May 8, and I was lucky to get mine a couple days early- all I can say so far, after coming from an iPhone, is that I &#8230; <a href="http://blog.builtbyprime.com/web/why-i-love-the-nexus-s-vs-iphone-4">Read more...</a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://www.flickr.com/photos/primestudios/5697097434/in/photostream"><img class="aligncenter" style="margin-bottom: 25px;" title="Nexus S and Apple iPhone" src="http://farm4.static.flickr.com/3595/5697097434_8e4e955240_z.jpg" alt="" width="640" height="450" /></a></p>
<p><a href="http://www.google.com/nexus/#/tech-specs">Google&#8217;s Nexus S</a> (mfg. by Samsung) will officially come out for Sprint on May 8, and I was lucky to get mine a couple days early- all I can say so far, after coming from an iPhone, is that I love this device. We decided that our shop had to diversify a bit, and because NFC was right up my electrical-engineering-alley, I hopped on the line with Sprint. My predispositions about Android were bad, we always made fun of our friends with Android-based phones because they were buggy and sluggish compared to the iPhone. However, these got broken with the Nexus S; I think the mixture of Google&#8217;s oversight, the 1GHz &#8220;Hummingbird&#8221; processor, and the latest release of Android (2.3) coined &#8220;Gingerbread&#8221; makes this snappy, and lets the features of Android shine.</p>
<p><span style="color:#ccc"><em>*Photographed with the case on, available from Sprint stores.</em></span></p>
<h3>From iPhone to Nexus S</h3>
<p><a href="http://www.flickr.com/photos/primestudios/5697096142/in/photostream"><img class="alignright" style="padding-bottom: 10px; padding-left: 15px; float: right;" title="Nexus S Settings" src="http://farm6.static.flickr.com/5185/5697096142_b924ca279a_m.jpg" alt="" width="216" height="211" /></a>I don&#8217;t think its fair to group the Nexus S into the same category as all Android devices, because it is right on par with the <a href="http://www.apple.com/iphone/specs.html">iPhone 4&#8242;s</a> touch sensitivity and reactiveness, which I don&#8217;t think can be said about any other little green robot devices right now. There is one thing that sums up my thoughts about these two devices after making the switch: <strong>All the standards and design rules on the iPhone make it very clean and organized, but also make it stale and less efficient for many tasks</strong>.</p>
<p>First of all, on the Nexus S you have 4 hardware &#8220;action&#8221; buttons instead of one, and I think this feature is really under-rated for how powerful it is. Putting all the inner-workings of Android and iOS aside, here are what these buttons open up:</p>
<ul>
<li>With the back button you have the control to &#8220;go back&#8221; to what you were doing last, which in most cases removes the need for a top or bottom bar in the browser and apps.</li>
<li>You can click the options button for more choices of what to do next, or application-specific settings.</li>
<li>The search button provides access to in-app searches (useful in contacts, Gmail, etc.)</li>
<li>The home button acts essentially the same as the home button on the iPhone.</li>
</ul>
<p>Not only do these features let you do things quicker on the Nexus S, but it also increases the screen real-estate in a many cases. The screen is already larger than the iPhones (4&#8243; vs. 3.5&#8243;), but the first thing I noticed when reading some CNN Mobile was that the story covered my whole screen (no bottom bar), which made it a much cleaner and immersive experience.</p>
<p style="text-align: center;"><a href="http://www.flickr.com/photos/primestudios/5696518905/in/photostream"><img class="aligncenter" style="margin-top: 25px;" title="Nexus S CNN Mobile" src="http://farm3.static.flickr.com/2555/5696518905_0be13c9f9f_z.jpg" alt="" width="640" height="444" /></a></p>
<h3>I Don&#8217;t Launch an App for Weather</h3>
<p>Another major feature I was a bit unsure about was this whole modular home screen thing; Windows has a pretty lack-luster integration of &#8220;widgets&#8221;, and I think thats why I was scared. However, after having this feature, it makes you realize how far behind Apple&#8217;s grid system is. Things that are important to me from my mobile: Twitter, Facebook, Weather, Calendar, and all my other apps. With the Android widgets I have the ability to make those my priorities, and instead of having to launch an app to browse tweets, or to see if I have meetings today, it is just a swipe away. You just can&#8217;t make certain things a &#8220;priority&#8221; in a square grid model- if Facebook is all I care about, then it can take up half my screen right when I turn on the phone, which is a powerful time saver.</p>
<h3>NFC and Hotspots.. Baby</h3>
<p><a href="http://www.flickr.com/photos/primestudios/5697097054/in/photostream/"><img class="alignleft" style="float:left;margin-bottom: 15px; margin-right: 15px;" title="Nexus S NFC Tags" src="http://farm4.static.flickr.com/3132/5697097054_7e899ded11.jpg" alt="" width="400" height="293" /></a>The entire controversy of &#8220;will NFC be big&#8221; has been put to rest in my book, <strong>NFC will change the mobile environment</strong>. I say this because we currently look at QR codes and SMS (text messaging) as a viable and useful way to trade information, and they are horribly time consuming and painful. If you haven&#8217;t experienced it yet, wait until you do the same thing by just passing your phone near another NFC device; its like &#8220;damn, that was easy&#8221;. I mean, imagine if every time you had to use your credit card you couldn&#8217;t swipe it, and you had to type in each number- thats the difference of NFC versus the current methods.</p>
<p>The Nexus S has a special &#8220;Tags&#8221; app which can read NFC tags that can contain text, web links, contact info, and much more. The Tags app also stores the tag information and allows you to bookmark your favorite tags. The last feature of the Tags app is pretty revolutionary, it allows you to turn your phone into an NFC tag, and transmit your choice of information. Say goodbye to apps like <a href="http://bu.mp">Bump</a>, with the Nexus S you can share everything a normal NFC tag can share, and even switch between an &#8220;active&#8221; tag, and ones you have created in the past. Last neat note, the biggest NFC tag manufacturer, NXP <a href="http://www.flickr.com/photos/primestudios/5697096656/in/photostream"><img class="alignright" style="padding-bottom: 10px; padding-left: 15px; padding-top:15px; float: right;" title="Nexus S Settings" src="http://farm3.static.flickr.com/2256/5697096656_f1e00a1b48_m.jpg" alt="" /></a> Semiconductors, has an app that allows you to read, write, and lock NFC tags, which makes this a &#8220;lab tool&#8221; for mobile dev&#8217;s like ourselves. Read what we have to say about <a href="http://blog.builtbyprime.com/business/high-tech-mobile-marketing-nfc-near-field-communication">NFC and mobile marketing</a>.</p>
<p>NFC is by far the coolest wireless feature on the Nexus S, but the other one to make mention of is the WiFi hotspots and tethering. I am actually typing this article from my phones wireless network, and it is using Sprint&#8217;s 3G network for all the data transfer (4G where available). I called Sprint and had them turn on the $30/mo feature, which they said I can cancel tomorrow and only pay for the day I used it ($1)- but so far, even at 3G speeds, it rocks. And yes, up to 4 of your friends can use the WiFi network too (Apple is reluctant to allow this). There is always the option to do USB tethering which may save some battery power.</p>
<p style="text-align: center;"><a href="http://www.flickr.com/photos/primestudios/5697095464/in/photostream"><img class="aligncenter" style="margin-top: 25px;" title="Nexus S" src="http://farm4.static.flickr.com/3330/5697095464_d6e0861f73_z.jpg" alt="" width="640" /></a></p>
<h3>Apps: Better or Worse</h3>
<p>I don&#8217;t think it is a secret that the iPhone paired with iOS makes the worlds most stable mobile device, but again, you run into the whole grid-based app layout, and top and bottom bar navigation. iPhone apps always &#8220;feel&#8221; like iPhone apps, however Android app&#8217;s seem to take on their own personality, which I have found to be great in most cases. The app&#8217;s have been pleasantly stable, nicely designed, and it is refreshing to have the entire screen to work with. This said, the worst thing about Android is the &#8220;App Market&#8221;- it looks like a third grader&#8217;s concept with an even worse implementation. This is where the Apple devices will beat the Nexus S and any Android devices, because they have a larger and more respected app community. However, both platforms have good apps, and both have crappy ones too, and in general all the major players like Facebook, Twitter, etc. have teams devoted to both.</p>
<h3>The Final Words</h3>
<p>I expect that I will run into some issues with the Nexus S, probably related to Android and particular bugs within third party apps, but as of right now, and as the title says, I love this phone. Here are just a few other side notes that I didn&#8217;t detail:</p>
<ul>
<li>The iPhone 4&#8242;s camera is a little better, but as a photographer, I want to get my photos right in the camera, so setting things like white balance, exposure, and having the option for black and white is great.</li>
<li>The web browser on the Nexus S still needs some work. The JavaScript handling falls short compared to the iPhone&#8217;s, which is becoming a huge component to the mobile web.</li>
<li>The power management widget is another example of how with one swipe and one tap I can turn off WiFi or Bluetooth, whereas the Apple method is pretty arduous.</li>
</ul>
<p>I am extremely happy that my Apple iOS shell was broken, it is kind of like seeing a forest through the trees- there are a lot of ways to make things happen on mobile, and Apple doesn&#8217;t have all the best ones right now. Will the iPhone 5 have better notifications, include NFC, and let me browse Twitter from my home screen? I hope so, because I love Apple, and want all the mobile companies to make things more usable and intuitive for everyone.</p>
<p style="text-align: center;"><a href="http://www.flickr.com/photos/primestudios/5696519351/in/photostream"><img class="aligncenter" style="margin-top: 25px;" title="Nexus S" src="http://farm3.static.flickr.com/2081/5696519351_e9bb7a1063_z.jpg" alt="" width="640" height="466" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.builtbyprime.com/web/why-i-love-the-nexus-s-vs-iphone-4/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clearing CodeIgniter Form Validation Rules</title>
		<link>http://blog.builtbyprime.com/php/clearing-codeigniter-form-validation-rules</link>
		<comments>http://blog.builtbyprime.com/php/clearing-codeigniter-form-validation-rules#comments</comments>
		<pubDate>Tue, 22 Mar 2011 19:05:36 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.builtbyprime.com/?p=1568</guid>
		<description><![CDATA[We recently had a case where we created a huge form that had separate sections that we needed to validate, we call them &#8220;modules&#8221;. Our goal was to send all the form data to a single save function, and then &#8230; <a href="http://blog.builtbyprime.com/php/clearing-codeigniter-form-validation-rules">Read more...</a>]]></description>
			<content:encoded><![CDATA[<p>We recently had a case where we created a huge form that had separate sections that we needed to validate, we call them &#8220;modules&#8221;. Our goal was to send all the form data to a single save function, and then that function could call each form validation function for the included modules. We ran into a small problem with Code Igniter running multiple form validation functions; more specifically, if the first form validation function gave an error, that error would not be cleared in the second form validation function and so on. This meant that all our validation scripts would &#8220;carry over&#8221; their errors, which is no good.</p>
<p>Our fix was to clear all the variables used in the <a href="http://codeigniter.com/user_guide/libraries/form_validation.html">Code Igniter Form Validation Class</a>, which basically sends it back to an empty state. Here is an example:</p>
<pre class="brush: php; title: ;">
&lt;?php
  //we POST to this function from our form
  function save() {
    $modules = array(
      'patient_info',
      'patient_history'
    );

    $this-&gt;load-&gt;library('form_validation');
    $errors = array();
    foreach($modules as $module) {
      $function = 'save_'.$module;
      $errors = $this-&gt;$function();
      //reset form validation class
      $this-&gt;form_validation-&gt;_field_data = array();
  	  $this-&gt;form_validation-&gt;_config_rules = array();
  	  $this-&gt;form_validation-&gt;_error_array = array();
  	  $this-&gt;form_validation-&gt;_error_messages = array();
  	  $this-&gt;form_validation-&gt;error_string = '';
    }
    //do checks on $error array, return or echo accordingly
  }

  function save_patient_info() {
    $this-&gt;form_validation-&gt;set_rules('first_name','First Name','required|xss_clean|max_length[300]');
    $this-&gt;form_validation-&gt;set_rules('email','Email Address','required|xss_clean|max_length[300]|valid_email');
    if ($this-&gt;form_validation-&gt;run() != FALSE) {
      //do work
      return TRUE;
    } else {
      return validation_errors();
    }
  }

  function save_patient_history() {
    $this-&gt;form_validation-&gt;set_rules('last_visit_date','Last Visit Date','required');
    $this-&gt;form_validation-&gt;set_rules('tetanus_shot','Tetanu Shot in past 5 years','required');
    if ($this-&gt;form_validation-&gt;run() != FALSE) {
      //do work
      return TRUE;
    } else {
      return validation_errors();
    }
  }
?&gt;
</pre>
<p>Remember that your global $_POST variable will remain set throughout the entirety of the all the function calls, so each function will validate against it, as it should.  This saves you from having to making a massive validation function, which may break if a particular module wasn&#8217;t included on the form. This was an easy way we found, if you have a better one, we would love to hear about it!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.builtbyprime.com/php/clearing-codeigniter-form-validation-rules/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A GUIDE to Simple Code Igniter Models</title>
		<link>http://blog.builtbyprime.com/php/a-guide-to-generic-code-igniter-models</link>
		<comments>http://blog.builtbyprime.com/php/a-guide-to-generic-code-igniter-models#comments</comments>
		<pubDate>Thu, 17 Feb 2011 00:09:36 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.primestudiosllc.com/?p=1364</guid>
		<description><![CDATA[After a lot database code, you realize that the majority of your methods take on the same structure. For a while now, I have started all of our Code Igniter models with five generic methods to interact with the database, &#8230; <a href="http://blog.builtbyprime.com/php/a-guide-to-generic-code-igniter-models">Read more...</a>]]></description>
			<content:encoded><![CDATA[<p>After a lot database code, you realize that the majority of your methods take on the same structure. For a while now, I have started all of our <a href="http://codeigniter.com/">Code Igniter</a> models with five generic methods to interact with the database, and they usually cover a good amount of any basic application&#8217;s needs. I am going to flip the CRUD acronym on end and use my own: GUIDE- standing for Get, Update, Insert, Delete, and Explicit.</p>
<h3>5 Methods, 5 Lines</h3>
<p>Let&#8217;s start with the core of what we are talking about, and the five lines of code (methods) that spell out GUIDE.</p>
<pre class="brush: php; title: ;">
 function get($a,$b=array(),$c=0){$d=$this-&gt;db-&gt;get_where($a,$b);$e=$d-&gt;result_array();if($c)return $e[0];return $e;}

function update($a,$b=array(),$c){$this-&gt;db-&gt;update($a,$c,$b);return $this-&gt;db-&gt;affected_rows();}

function insert($a,$b){$this-&gt;db-&gt;insert($a,$b);return $this-&gt;db-&gt;insert_id();}

function delete($a,$b=array()){$this-&gt;db-&gt;delete($a,$b);return $this-&gt;db-&gt;affected_rows();}

function explicit($a){$b=$this-&gt;db-&gt;query($a);if(is_object($b))return $b-&gt;result_array();return $b;}
</pre>
<p>You notice we minified those methods, because if we are happy with them time after time, why should they take up pixel real-estate on our screens? Let&#8217;s start with the GET method, and examine it un-minified:</p>
<pre class="brush: php; title: ;">
function get($table,$where=array(),$single=FALSE) {
  $q = $this-&gt;db-&gt;get_where($table,$where);
  $result = $q-&gt;result_array();
  if($single) {
    return $result[0];
  }
  return $result;
}
</pre>
<p>The real only explanation is the <strong>$single</strong> option in the function. Suppose you know you will only be getting one result back, maybe you specify a user ID in the <strong>$where</strong> array (see examples below). If this option is evaluated as true, the returned data array will be a single dimension. Essentially, if you are going to run the result data through a loop, you want a multidimensional array; if you the result as a simple array, use the single option.</p>
<p>The next three methods, Insert, Update, and Delete, just provide direct access to Code Igniters already-established active record tools, with return values that might be helpful in our application. You can refer to their use on the <a target="_blank" href="http://codeigniter.com/user_guide/database/active_record.html">Code Igniter Active Record Class</a> page.</p>
<pre class="brush: php; title: ;">
function insert($table,$data) {
  $this-&gt;db-&gt;insert($table,$data);
  return $this-&gt;db-&gt;insert_id();
}

function update($table,$where=array(),$data) {
  $this-&gt;db-&gt;update($table,$data,$where);
  return $this-&gt;db-&gt;affected_rows();
}

function delete($table,$where=array()) {
  $this-&gt;db-&gt;delete($table,$where);
  return $this-&gt;db-&gt;affected_rows();
}
</pre>
<p>The final method is named Explicit, and is for explicit queries. The only added logic is detection of an object on the query result. If the result is an object, the function returns a result array, and otherwise, it returns the raw query result (likely a boolean-compatible value).</p>
<pre class="brush: php; title: ;">
function explicit($query) {
  $q = $this-&gt;db-&gt;query($query);
  if(is_object($q)) {
    return $q-&gt;result_array();
  } else {
    return $q;
  }
}
</pre>
<h3>Basic Usage</h3>
<p>If you are not that familiar with Code Igniter, remember that it uses a fairly strict MVC architecture when it comes to the separation of controllers and models. Because of this you will want to place these methods inside a file in your model&#8217;s folder, perhaps &#8220;fav_model.php&#8221;. From your controller, you would call these methods like this:</p>
<pre class="brush: php; title: ;">
//get all users in the users table
$users = $this-&gt;fav_model-&gt;get('users');

//get the user with an ID=5 from the users table, return a single array
$user = $this-&gt;fav_model-&gt;get('users',array('id'=&gt;5),TRUE);

//update the users table with new data for user with ID=5
$data = array(
  'middle_name'=&gt;'Henry',
  'birthday'=&gt;'946684800'
);
$affected_rows = $this-&gt;fav_model-&gt;update('users',array('id'=&gt;5),$data);

//insert new user into the users table
$data = array(
  'first_name'=&gt;'Matt',
  'last_name'=&gt;'Gaidica',
  'password'=&gt;md5('abc123')
  'created'=&gt;time()
);
$id = $this-&gt;fav_model-&gt;insert('users',$data);

//delete user ID=5 from table users
$affected_rows = $this-&gt;fav_model-&gt;delete('users',array('id'=&gt;5));

//get all the information about user with ID=5 from users table
$data = $this-&gt;fav_model-&gt;explicit('SELECT * FROM users WHERE id=5');
</pre>
<h3>Limitations and Bewares</h3>
<p>There are some instances where these methods will not work, and where they might be outright dangerous to use. Here is a short list of just some instances that come to mind:</p>
<ul>
<li><strong>Your table names might change.</strong> If you use the table name as a variable in your model, and then change the table name inside the database, you will have to redo all those calls in your controllers. The alternative is to create a new method in your model for every table you are manipulating, so if it changes, you only rewrite the table name once.</li>
<li><strong>You want to sort the data, or get really specific.</strong> Unless you are using the Explicit method, there is no ordering beyond the default database behavior, and no limits or offsets to the data returned. Well-planned queries are important when dealing with large data sets, or highly-efficient applications.</li>
<li><strong>You want readable model methods.</strong> Creating one-fits-all code is sometimes counter-productive, and while the end result may work, it is hard for other developers (or on-lookers) to understand. A scaleable application is written so it makes sense to you and your team, even a year after writing it.</li>
</ul>
<h3>Thats All Folks</h3>
<p>This is an easy breezy way to start out your model, and when things get more complicated, you can expand on the methods used in this GUIDE. Hope you learned something new, any questions or comments are welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.builtbyprime.com/php/a-guide-to-generic-code-igniter-models/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code Igniter Query Times: Explicit vs. Active Record</title>
		<link>http://bytesofpi.tumblr.com/post/14479351964/codeigniter-active-record-vs-explicit</link>
		<comments>http://bytesofpi.tumblr.com/post/14479351964/codeigniter-active-record-vs-explicit#comments</comments>
		<pubDate>Wed, 16 Feb 2011 01:59:36 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.builtbyprime.com/?p=1506</guid>
		<description><![CDATA[When dealing with frameworks, such as Code Igniter, there is always a question of what type of overhead it adds to application. One rainy day not too long ago we ran some really simple tests on the difference between active &#8230; <a href="http://bytesofpi.tumblr.com/post/14479351964/codeigniter-active-record-vs-explicit">Read more...</a>]]></description>
			<content:encoded><![CDATA[<p>When dealing with frameworks, such as <a href="http://codeigniter.com/">Code Igniter</a>, there is always a question of what type of overhead it adds to application. One rainy day not too long ago we ran some really simple tests on the difference between active record queries, and explicit queries in CI, and decided it might be nice to share the results. There is always the question of &#8220;is it faster&#8221;, and while our results show explicit SQL queries to be faster, database execution time is almost always negligible when compared to PHP run time, or page load speeds.</p>
<h3>The Setup</h3>
<p>We wanted to keep this test pretty bare-bones, so we could really nail down the overhead of just the active record processing. We loaded up a fresh copy of Code Igniter version 1.7.3, and created a typical controller-model relationship. Next, we created a simple timer using PHP&#8217;s <a href="http://php.net/manual/en/function.microtime.php">microtime()</a> function, and wrapped our calls in a for-loop, so it would repeat 1000 times. On each loop it logged the time difference of just the query itself, and at the end it exported to a .csv file so we could chart it up.</p>
<h3>GET Query Times</h3>
<p><img style="margin-top:15px;" src="http://blog.builtbyprime.com/wp-content/uploads/get_active_record.png" alt="" title="get_active_record" width="650" height="416" class="aligncenter size-full wp-image-1535" /></p>
<p><strong>Average Times (s)</strong><br />
Explicit Query: 0.000168<br />
Active Record Query: 0.000309<br />
<br/></p>
<h3>INSERT Query Times</h3>
<p><img style="margin-top:15px;" src="http://blog.builtbyprime.com/wp-content/uploads/insert_active_record.png" alt="" title="insert_active_record" width="650" height="416" class="aligncenter size-full wp-image-1535" /></p>
<p><strong>Average Times (s)</strong><br />
Explicit Query: 0.000161<br />
Active Record Query: 0.000259<br />
<br/></p>
<h3>UPDATE Query Times</h3>
<p><img style="margin-top:15px;" src="http://blog.builtbyprime.com/wp-content/uploads/update_active_record.png" alt="" title="update_active_record" width="650" height="416" class="aligncenter size-full wp-image-1535" /></p>
<p><strong>Average Times (s)</strong><br />
Explicit Query: 0.000172<br />
Active Record Query: 0.000321<br />
<br/></p>
<h3>DELETE Query Times</h3>
<p><img style="margin-top:15px;" src="http://blog.builtbyprime.com/wp-content/uploads/delete_active_record.png" alt="" title="delete_active_record" width="650" height="416" class="aligncenter size-full wp-image-1535" /></p>
<p><strong>Average Times (s)</strong><br />
Explicit Query: 0.000172<br />
Active Record Query: 0.000321<br />
<br/></p>
<h3>Conclusions</h3>
<p>As you might see, and as you might expect, there is a &#8220;significant&#8221; overhead using CI&#8217;s active record; however, I put that in quotations because the time scale we are looking at is so darn small. When you are building applications that require 10e-5 precision on your database queries, well, you probably aren&#8217;t a general-purpose, curious developer.</p>
<p><img style="margin-top:15px;" src="http://blog.builtbyprime.com/wp-content/uploads/average-query-times.png" alt="" title="average_query_times" width="650" height="416" class="aligncenter size-full wp-image-1535" /></p>
]]></content:encoded>
			<wfw:commentRss>http://bytesofpi.tumblr.com/post/14479351964/codeigniter-active-record-vs-explicit/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tiny PHP: A Fun PHP Minifier</title>
		<link>http://blog.builtbyprime.com/php/tiny-php-a-fun-php-minifier</link>
		<comments>http://blog.builtbyprime.com/php/tiny-php-a-fun-php-minifier#comments</comments>
		<pubDate>Wed, 16 Feb 2011 00:43:40 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.builtbyprime.com/?p=1519</guid>
		<description><![CDATA[Tiny PHP is a little tool we put into our labs that performs some &#8220;minification&#8221; on PHP code. Is it a trivial and completely academic exercise because PHP doesn&#8217;t benefit from being smaller like CSS or Javascript? Yes. But it&#8217;s &#8230; <a href="http://blog.builtbyprime.com/php/tiny-php-a-fun-php-minifier">Read more...</a>]]></description>
			<content:encoded><![CDATA[<p>Tiny PHP is a little tool we put into our labs that performs some &#8220;minification&#8221; on PHP code. Is it a trivial and completely academic exercise because PHP doesn&#8217;t benefit from being smaller like CSS or Javascript? Yes. But it&#8217;s still kind of cool.</p>
<h3>What it does</h3>
<p>In short, the goal is to take a snippet, function, or page of PHP and condense it. It will replace variables, remove comments, and/or remove whitespace. To call this tool an obfuscator is not really right, but it does make code harder to read. It also has some fancy options that allow you to exclude certain variables from being replaced so your classe&#8217;s calls don&#8217;t get mushed up.</p>
<h3>What it doesn&#8217;t do</h3>
<p>The Tiny PHP tool does not attempt to minify function names, class names, or any references related to those objects. Were not trying to take your entire app and make it stupidly hard to maintain, there are lots of other programs out there to do that.</p>
<h3>How we use it</h3>
<p>There is really no reason to use this type of tool in production code. If you are just messing around though, it is sometimes nice to take a set of methods or functions, and condense them into four or five lines, if their only purpose is to simply exist and never be edited. Also, if an application has spiraled into a mess of variables that have absolutely no meaning, there becomes no difference between them being long and annoying, or short and sweet.</p>
<p>Give it a try, let us know about any bugs.</p>
<p><a target="_blank" href='http://labs.builtbyprime.com/tinyphp/' class='button inline'><em class='inline'>Take Me to Tiny PHP</em></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.builtbyprime.com/php/tiny-php-a-fun-php-minifier/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple PHP Pagination Code</title>
		<link>http://blog.builtbyprime.com/php/simple-php-pagination-code</link>
		<comments>http://blog.builtbyprime.com/php/simple-php-pagination-code#comments</comments>
		<pubDate>Thu, 03 Feb 2011 17:59:02 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.builtbyprime.com/?p=1448</guid>
		<description><![CDATA[The Problem: You have a data set (array) and you want to paginate it. You know the page you are on, and how many results per-page you want to display. The Solution: This simple script has an input of those &#8230; <a href="http://blog.builtbyprime.com/php/simple-php-pagination-code">Read more...</a>]]></description>
			<content:encoded><![CDATA[<p><b>The Problem:</b> You have a data set (array) and you want to paginate it. You know the page you are on, and how many results per-page you want to display.</p>
<p><b>The Solution:</b> This simple script has an input of those three things- data, current page, and items per page. It will return a new data set (array) only containing the data that would belong on the particular page you requested. It also returns how many pages there are in the set, and what page you are currently on (just for convenience). Lets take a look:</p>
<pre class="brush: php; title: ;">
&lt;?php
function paginate($data,$page=1,$per_page=5) {
  $min = (($page*$per_page)-$per_page)+1;
  $max = $page*$per_page;
  $count = 1;
  $page_data = array();
  foreach($data as $item) {
    if($count &gt;= $min &amp;&amp; $count &lt;= $max) {
      $page_data[] = $item;
    }
    $count++;
  }
  $pages = ceil(count($data)/$per_page);
  return array(
    'page_data'=&gt;$page_data,
    'pages'=&gt;$pages,
    'page'=&gt;$page
  );
}
?&gt;
</pre>
<p>It is not the hardest problem in the world, but it is interesting to solve! Let&#8217;s plug some stuff into it and see what happens. Also, because I found the variables to be a bit arbitrary, I threw it into my PHP minify script so its fun to look at.</p>
<pre class="brush: php; title: ;">
&lt;?php
function paginate($a,$b=1,$c=5){$d=(($b*$c)-$c)+1;$e=$b*$c;$f=1;$g=array();foreach($a as $h){if($f&gt;=$d&amp;&amp;$f&lt;=$e){$g[]=$h;}$f++;}$i=ceil(count($a)/$c);return array('page_data'=&gt;$g,'pages'=&gt;$i,'page'=&gt;$b);}

$data = array(1,2,3,4,5,6,7,8,9,10,11,12,13);

//get page 2 data, 4 items per-page
$page_info = paginate($data,2,4);
print_r($page_info);
?&gt;
</pre>
<p>The result in my browser is:</p>
<pre class="brush: xml; title: ;">
Array
(
  [page_data] =&gt; Array
    (
      [0] =&gt; 5
      [1] =&gt; 6
      [2] =&gt; 7
      [3] =&gt; 8
    )
  [pages] =&gt; 4
  [page] =&gt; 2
)
</pre>
<p>I hope that was the easiest way to present this, and maybe one of the easiest pagination scripts you can start with for your application. I use this inside of a Code Igniter library, and was pretty frustrated that most of the tutorials and methods are a bit much for the basics.  As always, let us know if you have questions, and thanks for stopping in.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.builtbyprime.com/php/simple-php-pagination-code/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Footer Fun with PHP, Part 3: WordPress Posts</title>
		<link>http://blog.builtbyprime.com/php/footer-fun-with-php-pt3-wordpress-posts</link>
		<comments>http://blog.builtbyprime.com/php/footer-fun-with-php-pt3-wordpress-posts#comments</comments>
		<pubDate>Tue, 01 Feb 2011 18:49:26 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.builtbyprime.com/?p=1431</guid>
		<description><![CDATA[Our final addition to the PHP footer chronicles is adding some basic information about our most recent blog posts. We have written about Getting Blog Posts from WordPress before, but will toss up a slightly different method in this post. &#8230; <a href="http://blog.builtbyprime.com/php/footer-fun-with-php-pt3-wordpress-posts">Read more...</a>]]></description>
			<content:encoded><![CDATA[<p>Our final addition to the PHP footer chronicles is adding some basic information about our most recent blog posts. We have written about <a href="http://blog.builtbyprime.com/php/getting-blog-posts-from-wordpress-in-php">Getting Blog Posts from WordPress</a> before, but will toss up a slightly different method in this post. One thing to note is that all WordPress installs are different, and might use different directory or subdomain setups. We chose to use a subdomain, and due to this, accessing <a href="http://codex.wordpress.org/The_Loop">The Loop</a> can be tricky because some server&#8217;s will not allow you to back-pedal into subdomain directories. Long-story-short, we will create a simple API from the WordPress install, and cURL into it.</p>
<p>In our main directory of our WordPress install (where wp-config.php lives) we will add a file called &#8220;api.php&#8221;, where we will build an array of recent posts, and then spit them out in JSON format.</p>
<pre class="brush: php; title: ;">
&lt;?php
// Include WordPress
define('WP_USE_THEMES', false);
require('wp-load.php');

$args = array();
if(!empty($_GET['limit'])) {
  $args['posts_per_page'] = $_GET['limit'];
}
query_posts($args);
if (have_posts()) {
  $posts = array();
  while (have_posts()) {
    the_post();
    $content = strip_tags($post-&gt;post_content);
    $limit = 239;
    $last_space = strpos($content,&quot; &quot;,$limit);
    $excerpt = substr($content,0,$last_space);
    $excerpt .= '...';

    $author_id=$post-&gt;post_author;
    $author_data = get_userdata($author_id);
    $author_name = ucfirst($author_data-&gt;user_nicename);

    $posts[] = array(
	'link'=&gt;get_permalink(),
	'title'=&gt;$post-&gt;post_title,
	'author'=&gt;$author_name,
	'excerpt'=&gt;$excerpt,
	'time'=&gt;strtotime($post-&gt;post_date)
	);
  }
  echo json_encode($posts);
} else {
  echo json_encode(array('error'=&gt;'no data'));
}
</pre>
<p>In this small routine we have an optional limit to the amount of posts we display, we build a custom-length excerpt, we get the authors name, and include the blog posts&#8217; link and post date. You can see this in action at <a href="http://blog.builtbyprime.com/api.php?limit=4">our blog&#8217;s api.php location</a>. Now you can interface to your blog, only retrieving the minimum amount of information you need, and parse it really easily without a bloated plugin. The next step is grabbing the information from your main website (or footer) using <a href="http://php.net/manual/en/book.curl.php">PHP&#8217;s cURL</a>.</p>
<pre class="brush: php; title: ;">
&lt;?php
$url = 'http://blog.builtbyprime.com/api.php?limit=4';
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5);
$data = curl_exec($ch);
curl_close($ch);
$blog_posts = json_decode($data,TRUE);
?&gt;
</pre>
<p>The only thing to point out here is that when we decode the JSON string, we set the second [optional] parameter in the function <a href="http://php.net/manual/en/function.json-decode.php">json_decode()</a> so it returns an array, and not an object- just a personal choice in this situation. In our particular footer, we only use the blog post title and author name, so while we have access to some of the other stuff, we just don&#8217;t use it right now.</p>
<pre class="brush: php; title: ;">
&lt;h4&gt;Blog&lt;/h4&gt;
&lt;ul&gt;
  &lt;?php foreach($blog_posts as $blog_post):?&gt;
    &lt;li&gt;&lt;a href='&lt;?=$blog_post['link']?&gt;'&gt;&lt;?=$blog_post['title']?&gt; &lt;em&gt;by &lt;?=$blog_post['author']?&gt;&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;?php endforeach;?&gt;
&lt;/ul&gt;
</pre>
<p>It doesn&#8217;t get too much easier, right? Hope you found something helpful, and hope you enjoyed our three part footer series! If you have any questions, or want to post a better method, please feel free to do so. Happy coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.builtbyprime.com/php/footer-fun-with-php-pt3-wordpress-posts/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Footer Fun with PHP, Part 2: Flickr</title>
		<link>http://blog.builtbyprime.com/php/footer-fun-with-php-pt2-flickr</link>
		<comments>http://blog.builtbyprime.com/php/footer-fun-with-php-pt2-flickr#comments</comments>
		<pubDate>Tue, 01 Feb 2011 17:54:35 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.builtbyprime.com/?p=1423</guid>
		<description><![CDATA[Following our Twitter PHP blog post, we need to talk about Flickr. Flickr continues to be our choice of a photo sharing tool, mainly because their API support, and we appreciate some of their smart server-side handling of images. This &#8230; <a href="http://blog.builtbyprime.com/php/footer-fun-with-php-pt2-flickr">Read more...</a>]]></description>
			<content:encoded><![CDATA[<p>Following our Twitter PHP blog post, we need to talk about <a href="http://www.flickr.com/photos/primestudios">Flickr</a>. Flickr continues to be our choice of a photo sharing tool, mainly because their API support, and we appreciate some of their smart server-side handling of images. This small tutorial is actually dead simple, because we will drop in the <a href="http://phpflickr.com/">PHP Flickr class phpFlickr</a>, which can be downloaded at that link. We have used this class many times, and have never had any issues for basic tasks.</p>
<p>First things first, you will need an API key to connect with the Flickr API, which you can get at the <a href="http://www.flickr.com/services/api/misc.api_keys.html">Flickr Services API Key</a> area. It will generate an API key and an application secret, but we will only use the API key in this walk-through. Once you have the phpFlickr class downloaded and on your server, getting your most recent public photos is a breeze.</p>
<pre class="brush: php; title: ;">
require_once('phpFlickr.php');
$flickr = new phpFlickr('YOUR_API_KEY');
$extras = 'description,url_sq,url_s,date_upload,path_alias';
$photos = $flickr-&gt;people_getPublicPhotos('46560602@N06','',$extras,4,1);
</pre>
<p>It is always nice to review the <a href="http://www.flickr.com/services/api/flickr.people.getPublicPhotos.html">Flickr API Doc&#8217;s</a> for the function you are working with, and look into the phpFlickr class to make sure you are addressing things correctly. In this instance, we are requesting the 4 most recent public photos from our Prime Flickr account- notice we must use our Flickr user id, which if you don&#8217;t know it, you can get it at <a href="http://idgettr.com/">idGettr</a>. In our string of &#8220;extras&#8221;, we request a couple different image sizes (square and small) because our layout uses one large image, and three small ones. Here is how we loop through them:</p>
<pre class="brush: php; title: ;">
&lt;h4&gt;Flickr&lt;/h4&gt;
&lt;?php $count=0; foreach($photos['photos']['photo'] as $photo):?&gt;
  &lt;?php if($count==0):?&gt;
    &lt;a target=&quot;_blank&quot; href=&quot;http://flickr.com/photos/&lt;?=$photo['pathalias']?&gt;/&lt;?=$photo['id']?&gt;/lightbox&quot;&gt;&lt;img src='&lt;?=$photo['url_s']?&gt;' /&gt;&lt;/a&gt;
     &lt;h5&gt;&lt;?=$photo['title']?&gt; &lt;em&gt;&lt;?=date('F j, Y',$photo['dateupload'])?&gt;&lt;/em&gt;&lt;/h5&gt;
     &lt;ul class='flickr'&gt;
   &lt;?php else:?&gt;
      &lt;li&gt;&lt;a target=&quot;_blank&quot; href=&quot;http://flickr.com/photos/&lt;?=$photo['pathalias']?&gt;/&lt;?=$photo['id']?&gt;/lightbox&quot;&gt;&lt;img src='&lt;?=$photo['url_sq']?&gt;'/&gt;&lt;/a&gt;&lt;/li&gt;
    &lt;?php endif;?&gt;
    &lt;?php $count++; endforeach;?&gt;
&lt;/ul&gt;
</pre>
<p>We are using PHP short-coding inside of the HTML to make things really clean and easy to read. You will also notice we make things a bit more complicated here because our first image gets formatted a bit differently than the last three. We hope this gives you something you didn&#8217;t know, or helped you along the way. Please let us know of any questions!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.builtbyprime.com/php/footer-fun-with-php-pt2-flickr/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Footer Fun with PHP, Part 1: Twitter</title>
		<link>http://blog.builtbyprime.com/php/footer-fun-with-php-pt1-twitter</link>
		<comments>http://blog.builtbyprime.com/php/footer-fun-with-php-pt1-twitter#comments</comments>
		<pubDate>Tue, 01 Feb 2011 17:52:16 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.builtbyprime.com/?p=1406</guid>
		<description><![CDATA[We recently rebuilt our footer and made sure to add some of our social outlets, like our blog posts, Twitter feed, and Flickr feed. This can sometimes cause a headache for a developer because there are so many choices on &#8230; <a href="http://blog.builtbyprime.com/php/footer-fun-with-php-pt1-twitter">Read more...</a>]]></description>
			<content:encoded><![CDATA[<p>We recently rebuilt our footer and made sure to add some of our social outlets, like our blog posts, Twitter feed, and Flickr feed. This can sometimes cause a headache for a developer because there are so many choices on how to grab feeds, and we wanted to share what we found to be the best, and most simple in PHP. </p>
<p>We will start with Twitter, and most of our code can be attributed to <a href="http://bavotasan.com/tutorials/how-to-create-a-twitter-feed-on-your-web-site/">bavotasan.com&#8217;s Twitter Feed article</a>; it is a nice script that plain-and-simple gets a twitter feed. We modified the code provided though, so instead of it actually creating the HTML elements, we get an array back so we can mess with it ourselves. Here is the code for a Twitter class, in a file we named &#8220;twitter.php&#8221;. </p>
<pre class="brush: php; title: ;">
&lt;?php
class Twitter {
  function get_tweets($username,$num) {
    $url = &quot;http://search.twitter.com/search.json?q=from:&quot;.$username .&quot;&amp;rpp=&quot;.$num;
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5);
    $data = curl_exec($ch);
    curl_close($ch);

    $tweets = json_decode($data);
    $tweet_array = array();
    for($x=0;$x&lt;$num;$x++) {
      $str = ereg_replace(&quot;[[:alpha:]]+://[^&lt;&gt;[:space:]]+[[:alnum:]/]&quot;,&quot;&lt;a href=\&quot;\&#92;&#48;\&quot;&gt;\&#92;&#48;&lt;/a&gt;&quot;, $tweets-&gt;results[$x]-&gt;text);
      $pattern = '/[#|@][^\s]*/';
      preg_match_all($pattern, $str, $matches);	

      foreach($matches[0] as $keyword) {
        $keyword = str_replace(&quot;)&quot;,&quot;&quot;,$keyword);
        $link = str_replace(&quot;#&quot;,&quot;%23&quot;,$keyword);
        $link = str_replace(&quot;@&quot;,&quot;&quot;,$keyword);
        if(strstr($keyword,&quot;@&quot;)) {
          $search = &quot;&lt;a href=\&quot;http://twitter.com/$link\&quot;&gt;$keyword&lt;/a&gt;&quot;;
        } else {
          $link = urlencode($link);
          $search = &quot;&lt;a href=\&quot;http://twitter.com/#search?q=$link\&quot; class=\&quot;grey\&quot;&gt;$keyword&lt;/a&gt;&quot;;
        }
        $str = str_replace($keyword, $search, $str);
      }
      //var_dump($tweets-&gt;results[$x]);
      $tweet_array[] = array('text'=&gt;$str,'created'=&gt;strtotime($tweets-&gt;results[$x]-&gt;created_at));
    }
    return $tweet_array;
  }
}
</pre>
<p>You will notice we do not close the PHP tag at the end, this is best-practice in a PHP-only file, mostly to eliminate any type of whitespace issues/errors. Now, we can retrieve tweets (in your footer if you want) from Twitter like this:</p>
<pre class="brush: php; title: ;">
&lt;?php
require_once('twitter.php');
$twitter = new Twitter;
$tweets = $twitter-&gt;get_tweets('primestudios',3);
?&gt;
</pre>
<p>Remember, our Twitter class is replacing all links inside the tweet with an actual HTML anchor, so most of the heavy-lifting is done. Lastly, we just need to loop through the tweets to display them, having access to two array elements- &#8220;text&#8221; of the tweet, and the &#8220;created&#8221; date in UNIX. Here is the actual code we use in our footer.</p>
<pre class="brush: php; title: ;">
&lt;h4&gt;Twitter&lt;/h4&gt;
&lt;ul&gt;
  &lt;?php foreach($tweets as $tweet):?&gt;
    &lt;li&gt;&lt;p&gt;&lt;?=$tweet['text']?&gt; &lt;em&gt;&lt;?=date('M j',$tweet['created'])?&gt;&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
  &lt;?php endforeach;?&gt;
&lt;/ul&gt;
</pre>
<p>Of course the CSS will be up to you, and notice that we use the common UNIX date format, so we convert it to something human-readable of our choice with <a href="http://php.net/manual/en/function.date.php">PHP&#8217;s date() function</a>. Maybe this can save you an hour or so of work, because thats what sharing is all about! If you need help, please let us know.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.builtbyprime.com/php/footer-fun-with-php-pt1-twitter/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

