php采集新闻文章标题并保存为txt文档

<?php
$txtnames =”config/Caiji_News_title.txt”;
header(“Content-type: text/html; charset=utf-8;refresh:3000;”);
set_time_limit(0);
$imgline=””;
function preg_substr($start, $end, $str)
{
$temp = preg_split($start, $str);
$content = preg_split($end, $temp[1]);
return $content[0];
}
function str_substr($start, $end, $str)
{
$temp = explode($start, $str, 2);
$content = explode($end, $temp[1], 2);
return $content[0];
}
function microtime_float()
{
list($usec, $sec) = explode(” “, microtime());
return ((float)$usec + (float)$sec);
}
function getiurl($id)
{
global $imgline;
$str=$imgline[$id];
return $str;
}
$abcd=file_get_contents(“网址”);
$hello = explode(‘</li>’,str_substr(‘开始’, ‘结束’, $abcd));

$myfile = fopen($txtnames, “w”) or die(“采集失败!请检查采集规则!”);

for($index=0;$index<count($hello)-1;$index++)
{
$hello[$index]=str_substr(‘这之后’, ‘这之前’, $hello[$index]);
echo $hello[$index].”</br>”;
fwrite($myfile, $hello[$index].”
“);
}

fclose($myfile);

?>

未经允许不得转载:SEO_整站优化_网站优化公司 » php采集新闻文章标题并保存为txt文档

赞 (0)
标签: