title: PHP to retrieve latest tweet
body: <p>I am currently using the following code to retrieve the latest tweet from my Twitter feed:</p>
  
  <pre><code>&lt;?php
      $username='myUsername';
      $format = 'json';
      $tweet = json_decode(file_get_contents("http://api.twitter.com/1/statuses/user_timeline/{$username}.{$format}"));
      $latestTweet = htmlentities($tweet[0]-&gt;text, ENT_QUOTES);
      $latestTweet = preg_replace('/http:\/\/([a-z0-9_\.\-\+\&amp;\!\#\~\/\,]+)/i', '&lt;a href="http://$1" target="_blank"&gt;http://$1&lt;/a&gt;', $latestTweet);
      $latestTweet = preg_replace('/@([a-z0-9_]+)/i', '&lt;a href="http://twitter.com/$1" target="_blank"&gt;@$1&lt;/a&gt;', $latestTweet);
      echo '&lt;p class="inset white"&gt;'.$latestTweet.'&lt;/p&gt;';
  ?&gt;
  </code></pre>
  
  <p>On MAMP, this works perfectly, however on my live site, I get nothing, not even a server side error message. I read on a similar post that this may be something to do with <code>allow_url_fopen = On</code> not being set in php.ini, but setting that appears to have made no difference.</p>
  
  <p>Not withstanding the fact that Twitter may have changed their policy on usage of the API (which I don't believe they have), then I'm lost as to what could be the problem.</p>