Tweeting from PHP

Just found this, awesomely compact code!

Tweeting from PHP – Fabien Potencier.

function tweet($message, $username, $password)
  $context = stream_context_create(array(
    'http' => array(
      'method'  => 'POST',
      'header'  => sprintf("Authorization: Basic %s\r\n",
          "Content-type: application/x-www-form-urlencoded\r\n",
      'content' => http_build_query(array('status' => $message)),
      'timeout' => 5,
  $ret = file_get_contents('',
     false, $context);

  return false !== $ret;

tweet('From PHP, yeah...', 'fabpot', 'Pa$$');

I love PHP.

This entry was posted in programming. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>