yii的控制器的方法层
/**
* yii框架中的采集clllect
* @return
*/
public function actionCollect(){
$url="http://www.cnblogs.com/aggsite/SideRight";
$res=file_get_contents($url);
//正则表达式
$reg1='#<a href="http://news.cnblogs.com/">最新新闻</a>(.*)><a href="/aggsite/topviews">48小时阅读排行</a>#isU';
preg_match($reg1, $res, $arr1);
$reg2='#<li><a href="(.*)" target="_blank" οnmοuseοver=".*">(.*)</a></li>#isU';
preg_match_all($reg2, $arr1[1], $arr2);
// print_r($arr2);
return $this->render('caiji',['data'=>$arr2]);
}
view层
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>采集的页面显示</title>
</head>
<body>
<table class="table" border="1">
<?php foreach ($data[2] as $key => $value): ?>
<tr>
<td><?=$data[2][$key]?></td>
<td><?=$data[1][$key]?></td>
</tr>
<?php endforeach ?>
</table>
</body>
</html>