<?php
$url = "http://www.xxx.com/";
$data = file_get_contents($url);
//获取html中某个div中的信息
preg_match('/<div.*?class=\"dyw820_text_List\".*?>(.*?)<\/div>/is',$data,$match);
$info = $match[1];
// var_dump($info);die;
//匹配a链接中的标题和链接
preg_match_all('/<a.*?href="(.*?)">(.*?)<\/a>/', $info, $match2);
$alls = $match2[0];
// var_dump($alls);die;
$content = [];
foreach ($alls as $key => $value) {
preg_match_all('/<a\s*href=\"(.*?)\".*?>(.*?)<\/a>/',$value,$array);
$temp = [];
foreach ($array as $k2 => $v2) {
if ($k2==0) {
$temp['title'] = trim(trim(strip_tags($v2[0]),"|"));
}
if ($k2==1) {
$temp['src'] = strip_tags($v2[0]);
}
}
$content[] = $temp;
}
var_dump($content);
?>
网友评论