Posted By

kijtra on 12/17/10


Tagged

twitter shorturl


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Some0ne


Shorten URL to Twitter "t.co"


 / Published in: PHP
 

  1. function t_co($url){
  2. $user='[Your Twitter Account Name]';
  3. $pass='[Your Twitter login Password]';
  4.  
  5. $params=array(
  6. 'url'=>$url,
  7. 'session[username_or_email]'=>$user,
  8. 'session[password]'=>$pass,
  9. 'commit'=>'LOGIN'
  10. );
  11.  
  12. $ch=curl_init('http://twitter.com/share');
  13. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  14. curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
  15. curl_setopt($ch,CURLOPT_POST,TRUE);
  16. curl_setopt($ch,CURLOPT_POSTFIELDS,$params);
  17. curl_setopt($ch,CURLOPT_HTTPHEADER,array('Expect:'));
  18. $output=curl_exec($ch);
  19. curl_close($ch);
  20.  
  21. preg_match('/<textarea[^>]+>([^<]+)<\/textarea>/',$output,$match[1]);
  22. if(!empty($match[1][1])){
  23. return trim($match[1][1]);
  24. }
  25. }
  26.  
  27.  
  28. # Example
  29.  
  30. echo t_co('http://google.co.jp/');

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: kijtra on December 17, 2010

this snippet is unofficial...

You need to login to post a comment.