0
我在我的代碼中有一段使用file_get_contents從給定網頁抓取url。我的代碼中還有一段代碼,用於掃描數組中每個鏈接值的標題。 我想結束了具有類似於這樣的數組:file_get_contents不保存到數組
Array(
Google => array(
[title] => Google
[link] => http://www.google.com
)
)
但沒有值保存到我的陣列,即使我不能檢測到任何錯誤
$links = Array();
$URL = 'http://www.theqlick.com'; // change it for urls to grab
$file = file_get_contents($URL);
// grabs the urls from URL
if(strlen($file)>0) {
$links[] = preg_match_all("/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/", $file, $links);
}
function Titles() {
global $links;
$str = implode('',array_map('file_get_contents',$links));
error_reporting(E_ERROR | E_PARSE);
$titles = Array();
if(strlen($str)>0) {
$titles[] = preg_match_all("/\<title\>(.*)\<\/title\>/", $str, $title);
return $title;
return $links;
}
}
$newArray = array();
$j = 0;
foreach($links as $key => $val){
$newArray[$key] = array('link' => $val, 'title' => $title[1][$j++]);
}
print_r($newArray);
不分配'preg_match_all'的返回值,這不是它是如何工作的。當你不在任何地方調用它時,這裏的'Titles'函數在做什麼?爲什麼它有兩個'return'語句? – DCoder