Home > Backend Development > PHP Tutorial > PHP method to get the latest news from twitter sample code

PHP method to get the latest news from twitter sample code

怪我咯
Release: 2023-03-13 17:02:02
Original
1597 people have browsed it

Twitter(非官方汉语通称推特)是一家美国社交网络及微博客服务的网站,是全球互联网上访问量最大的十个网站之一。是微博客的典型应用。它可以让用户更新不超过140个字符的消息,这些消息也被称作“推文(Tweet)”。这个服务是由杰克·多西在2006年3月创办并在当年7月启动的。Twitter在全世界都非常流行, 据Twitter现任CEO迪克·科斯特洛宣布,截至2012年3月,Twitter共有1.4亿活跃用户,Twitter被形容为“互联网的短信服务”。

这篇文章主要介绍了php获取twitter最新消息的方法,涉及php操作curl及正则替换的技巧,非常具有实用价值,需要的朋友可以参考下

<?php
function get_status($twitter_id, $hyperlinks = true) {
  $c = curl_init();
  curl_setopt($c, CURLOPT_URL, "http://twitter.com/statuses/user_timeline/$twitter_id.xml?count=1");
  curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  $src = curl_exec($c);
  curl_close($c);
  preg_match(&#39;/<text>(.*)<\/text>/&#39;, $src, $m);
  $status = htmlentities($m[1]);
  if( $hyperlinks ) $status = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\\0\">\\0</a>", $status);
  return($status);
}
?>
Copy after login

The above is the detailed content of PHP method to get the latest news from twitter sample code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template