我使用以下代码从Twitter中提取一些用户名。我做过到目前为止是 得到这样的:修改PHP代码以从文档中提取特定字符串
[0] => com/USERNAME/statuses/[email protected]
[1] => com/ANOTHER_USERNAME/statuses/[email protected]
,这是我的代码..我怎么能只提取用户名?
$file = file_get_contents("http://search.twitter.com/search.rss?q=twitter");
$file = strip_tags($file);
preg_match_all("([a-z0-9!#$%&'*+/=?^_`{|}~-]*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)\b)siU", $file, $matches);
echo '<pre>';
print_r($matches);
echo '</pre>';
我这样做是使用SimpleXML但我只得到第一个结果
$url="http://search.twitter.com/search.atom?q=hello";
$twitter_xml = simplexml_load_file($url);
foreach ($twitter_xml->entry->author as $key) {
$author = $key->{"uri"};
echo"<li><h5>$author</h5></li>";
}
所以是模式总是'com'斜杠用户名斜线?如果是这样,正则表达式是不必要的... – lonesomeday 2012-02-08 21:52:28
看到你的其他问题:http://stackoverflow.com/questions/9199041/how-to-extract-the-content-of-uri-uri-in-a-xml-document – salathe 2012-02-08 21:53:17