电脑安全

您当前的位置:主页 > 电脑安全 >

php preg_match获取新浪新闻代码-网络编程

来源:[db:来源]标题:   最新新闻    编辑:电脑技术全能网 时间:2019-09-18 17:59

原标题:php preg_match获取新浪新闻代码-网络编程
   <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=gb2312"/> <title>最新消息</title> <style> body { background:#000000; padding:10px; font-size:12px; margin:10px; text-align:center; } #main { background:#8B9C0D; width:900px; margin:0px auto; } .mleft,.mmid,.mright { float:left; } .mleft,.mright { background:#ABCDEF; width:300px; float:left; } .mmid { background:#FECDBA; width:300px; float:left; } #footer { background:#EB5566; height:80px; margin:0px auto; width:900px; } a { display:block; text-align:left; } a:hover { font-size:13px; color:#FF0000; } a:visited { color:#000000; background:#FFC080; } </style> </head> <body> <div id="main"> <div class="mleft"><?php$str = file_get_contents("http://news.163.com/rank/");preg_match_all("#<div class="s3"><h6>(.*)</h6></div>#i",$str,$match);for($i=0; $i<count($match[0]); $i++){ echo "tttt".preg_replace("#(<div.*h6>)(.*)(</h6></div>)#i","/2",$match[0][$i])."n";}?> </div> <div class="mmid"><?php$str = file_get_contents("http://news.sina.com.cn/hotnews/");preg_match_all("#<span style='padding-left:6px'>(.*)</span></td>#i",$str,$match);for($i=0;$i<count($match[0]);$i++){ echo "tttt".preg_replace("#<span style='padding-left:6px'>(.*)</span></td>#i","/1",$match[0][$i])."n";}?> </div> <div class="mright"><?php$str = file_get_contents("http://news.qq.com/paihang.htm");preg_match_all("#<td align="left" class="left">(.*)</td>#i",$str,$match);for($i=0;$i<count($match[0]);$i++){ echo "tttt".preg_replace("#<td align="left" class="left">(.*)</td>#i","/1",$match[0][$i])."n";}?> </div> </div> <div id="footer"></div> </body></html>