首頁 >後端開發 >php教程 >php 网页截取新闻代码_PHP教程

php 网页截取新闻代码_PHP教程

WBOY
WBOY原創
2016-07-14 10:09:33907瀏覽

function Get_news($url,$count)

{
$handle = fopen($url,"r"); 
$c = 0;
while(($line = fgets($handle,1024)) && ($c
{
//$ptr2= "/(.*)/";
$ptr= "/(.*)/";
 
preg_match_all($ptr,$line,$str,PREG_SET_ORDER);
if($str)
{
$res[$c]= strip_tags($str[0][2]);
//$res[$c][1] = $url."admin/view_n.php?id=".$str[0][1];
$c = $c+1;
 
 
}
print_r($res[$c]);
}
return $res;
}
 
 
 
 
$url = "http://stu.gdmc.edu.cn/";
$count = 7;
//echo"
";
$result=Get_news($url,$count);
 
    foreach ($result as $key => $value) {
    echo iconv("gb2312", "UTF-8", $value)."
";//
    }
 
 
//print_r(Get_news($url,$count));
//echo"";
?> 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/477644.htmlTechArticle?php function Get_news($url,$count) { $handle = fopen($url,r); $c = 0; while(($line = fgets($handle,1024)) ($c$count)) { //$ptr2= /a href=\\/html\/xiaonaxinwen(.*)\(.*)\/a/; $ptr= /...
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn