Код парсинга xml сохранив url и title
set_time_limit(0);
$url = "http://history-autocars.ru/sitemap.xml";
function FetchUrl($url, $postvars, $timeout, $ref, $blank){
sleep($timeout);
echo @date("r")." fetching $url \r\n";
$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_TIMEOUT,30);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
$result = curl_exec($ch);
if($blank == "1"){
$result = preg_replace("/\n/", "", $result);
$result = preg_replace("/\r/", "", $result);
}
curl_close($ch);
return $result;
}
$page = FetchUrl($url, NULL, NULL, NULL, NULL);
preg_match_all("!<loc>(.*?)<\/loc>!si", $page, $out);
$fp=fopen("pars_title.txt","w");
foreach($out[1] as $link){
$page = FetchUrl($link, NULL, NULL, NULL, NULL);
file_put_contents("log.txt",$page);
preg_match("!<title>(.*?)<\/title>!si", $page, $tit);
echo '".$link."|".$tit[1]."'; flush();
fwrite($fp,'<title>'.$tit[1].'</title>'.'<loc>'.$link.'<loc>'."\r\n");
}
fclose($fp);