利用正则表达式提取内容信息
系统介绍 45°C 商城系统,以 Thinkphp5.0 + Uniapp + Layui2.9 + Vue 为技术基石,精心打造出的全新 MINI 商城应用。其功能覆盖全面,无论是 PC 商城、H5 商城,还是公众号商城、微信小程序以及抖音小程序的制作都能完美胜任。采用标准系统结合插件模式开发,用户能够极为便捷地定制专属的个性模块。整个系统,从程序设计到 UI 呈现,都秉持着一贯的小而美理念。程
0
<?php
//error_reporting(0);
$date=date("Ymd");
//echo $date;
$url="http://top.finance.sina.com.cn/ws/GetTopDataList.php?top_type=day&top_cat=all&top_time=".$date."&top_show_num=20&top_order=ASC";
$doc=file_get_contents($url);
header("Content-Type:text/html;charset=gb2312");//UNICODE转GB2312
//echo $doc;
preg_match_all('/"url":".*l/U',$doc,$article);//获取文章列表
$article=current($article);//二维数组转一维数组
//print_r($article);
$rule="/\"url\":(.*)\"\"/";
function OnlyUrl($string){
$string=stripslashes($string);
$string=str_replace('"url":"',"",$string);
return $string;
}
function GetTitle($url){ //获取文章标题
$doc=file_get_contents($url);
$rule="/<h1 (.*)<\/h1>/";
preg_match($rule,$doc,$result);
echo $result;
}
foreach($article as &$value){
$value=OnlyUrl($value);
}//提取了URL
?><?php
function GetTitle($url){ //获取文章标题
$rule="/<h1 (.*)<\/h1>/";
preg_match_all($rule,$doc,$result);
$rule="/>(.*)</";//截掉<h1></h1>
preg_match($rule,$result[0][1],$title);
return $title[1];
}
function GetContent($url){
$doc=file_get_contents($url);//打开网页
// echo $doc;
$rule="/publish_helper(.*)publish_helper_end/xs";
preg_match($rule,$doc,$result);//取出正文部分
//echo $result[0];
$rule="/publish_helper(.*)<\/blockquote>/xs";
preg_match($rule,$result[0],$out);//取出链接部分
//print_r($out);
$content=str_replace($out[0],"",$result[0]);//提取纯文字段的内容
echo $content;
}
?>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号