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>
本文地址:http://www.phprm.com/code/f776a0f00937c91e4579395a9911eaa4.html
转载随意,但请附上文章地址:-)