我看到有些東西看起來像,但不一樣的,我希望你能幫助:問題,PHP和正則表達式
我試圖通過
解析YouTube搜索執行從YouTube搜索結果的第一個結果結果頁面,找到這個:(屬於第一視頻)
<img alt="Thumbnail" src="http://i4.ytimg.com/vi/kUJLn7645Zs/default.jpg">
的話,我想要得到的視頻代碼是這樣的:(kUJLn7645Zs)
這是我的代碼和一些事情不工作,請協助
$res = file_get_contents("http://www.youtube.com/results?search_query=take+me");
preg_match_all('/<img\s[a-zA-Z0-9=\'\":\/.()[email protected]&\s]*>/',$res,$matches);
$str = $matches[0][0];
$tempArray = array();
$tempArray = explode('/',$str);
echo $tempArray[count($tempArray) - 2];
爲什麼你使用'preg_match_all()'如果你只想在第一個結果? – Phil
實際上我想要第一個5,這是一個例子 –
,如果你可以使用zend,使用[youtube api](http://code.google.com/intl/fr-FR/apis/youtube/2.0/developers_guide_php。 HTML#Searching_for_Videos)會比加載一個頁面 – Enki