1
我試圖從網站獲取一些圖像,但由於不同的文件擴展名已經得到難倒...PHP找出第二節比賽
我在preg_match_all()
if (preg_match_all('~http://foo.com/foo_(.*?).(.*?)~i', $returned_content, $matches)) {
2場比賽
月1日是IMG名和第2個是IMG的擴展,並想找出每個分機是什麼,所以我可以稍後在代碼中使用它:
更新,全碼:
//cURL function here get_data()
$returned_content = get_data('http://foo.com/page/2');
if (preg_match_all('~http://foo.com/foo_(.*?)\.(.*?)~i', $returned_content, $matches)) {
foreach ($matches[1] as $key) {
$file = 'http://foo.com/foo_' . $key . 'correct extension';// Need to have correct extension here
echo '<img src="' . $file . '" alt="" />';
}
}
我假設你想通過轉義它來創建一個文字'.':'\ .'? – Wiseguy
您可能需要將HTML讀取到HTML解析器中並選擇img src的值。正則表達式並不是真正解決這個問題的最好方法。 – dnagirl