21,887
社区成员
发帖
与我相关
我的任务
分享
<?php
//取得指定位址的内容,并储存至text
$text=file_get_contents('https://www.qq.com');
//去除换行及空白字元(序列化内容才需使用)
//$text=str_replace(array("r","n","t","s"), '', $text);
//取出div且id为PostContent的内容,并储存至阵列match
preg_match('/<ul[^>]*id="honey-focus-list"[^>]*>(.*?)广告标签 -->/si',$text,$match);
//印出match[0]
print($match[0]);
?>
<a href="https://www.qq.com/b/334728/7555246.html?fpa=15801&fpos=4" mg-stat-lob="fpa=15801&fpos=4" target="_blank" data-img="https://1img.qq.com/preview/cms_icon/2020/2/16/02/20200216222536277.jpg_2048x550.jpg" data-bgcolor="#635cff">
<a href="https://www.qq.com/b/334728/7555246.html?fpa=15801&fpos=4" mg-stat-lob="fpa=15801&fpos=4" target="_blank" data-img="https://1img.qq.com/preview/cms_icon/2020/2/16/02/20200216222536277.jpg_2048x550.jpg" data-bgcolor="#635cff">
preg_match_all("/(?<=data-img=\")[^\s^\"]*/",$str,$matches);
<?php
header("content-type:text/html,charset=utf-8;");
// $text=file_get_contents('https://www.qq.com');
$text='<a href="https://www.qq.com/b/334728/7555246.html?fpa=15801&fpos=4" mg-stat-lob="fpa=15801&fpos=4" target="_blank" data-img="https://1img.qq.com/preview/cms_icon/2020/2/16/02/20200216222536277.jpg_2048x550.jpg" data-bgcolor="#635cff">测试</a>
<a href="https://www.qq.com/b/334728/7555246.html?fpa=15801&fpos=4" mg-stat-lob="fpa=15801&fpos=4" target="_blank" data-img="https://1img.qq.com/preview/cms_icon/2020/2/16/02/20200216222536277.jpg_2048x550.jpg" data-bgcolor="#635cff">测试</a>';
$text=preg_replace('/<a.+data-img="([^"]+)"[^\/]+\/a>/','<img src="$1" />',$text);
echo($text);
?>