# [PHP]用15行PHP來Twitter!

- URL: https://justfly.idv.tw/php%e7%94%a815%e8%a1%8cphp%e4%be%86twitter/
- 日期: 2009-06-19
- 分類: WEB&amp;RIA
- 標籤: php, SNS, twitter

就降子15行

在任何可以用PHP的地方開始Twitter

```
function tweet($message, $username, $password)
{
    $context = stream_context_create(array( 
        'http' => array( 
        'method' => 'POST', 
        'header' => sprintf("Authorization: Basic %s\r\n", base64_encode($username.':'.$password)). 
            "Content-type: application/x-www-form-urlencoded\r\n", 
        'content' => http_build_query(array('status' => $message)), 
        'timeout' => 5, 
        ), 
    )); 
    $ret = file_get_contents('http://twitter.com/statuses/update.xml', false, $context); 

    return false !== $ret;
}
```

不過前提是php.ini 中的 file_get_contents得先打開才行
