我使用以下代碼從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