技术笔记
当前位置:首页 > 商学院 > 技术笔记 > 正文内容

技术笔记

php从HTML中获取所有图片

豫唐网络2023-03-07 13:24422

从HTML中获取所有图片。

应用案例

$txt='<p>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;最近访问站点:实时显示正在使用豫唐主题或者插件的站点。
</p>
<p style="text-align: center;">
    <img class="ue-image" src="https://www.ytecn.com/zb_users/upload/2022/03/202203201647760489897832.png" title="豫唐商务服务平台大数据中心" alt="豫唐商务服务平台大数据中心"/>
</p>';
$array=RemovePHPCode($txt);
print_r($array);

输出结果为:

Array ( [0] => https://www.ytecn.com/zb_users/upload/2022/03/202203201647760489897832.png )

函数

function GetImagesFromHtml($html)
{
    $pattern = "/<img[^>]+src=[\\'|\"](.*?)[\\'|\"][^>]*>/i";
    //$pattern = '/<img[^>]+src="([^">]+)"[^>]*>/i'; //沉水
    preg_match_all($pattern, $html, $matches);
    $array = is_array($matches[1]) ? $matches[1] : array();
    foreach ($array as $key => $value) {
        $array[$key] = htmlspecialchars_decode($array[$key]);
    }
    $array = array_unique($array);
    return $array;
}

扫描二维码推送至手机访问。

版权声明:本文由汤阴县豫唐网络科技有限公司发布,如需转载请注明出处。

本文链接:https://www.ytecn.com/post/569.html

分享给朋友:

相关文章

php将编码转换为UTF8

php将编码转换为UTF8

主要用于编码不统一导致出现乱码的情况,此函数会自动监测非UTF8编码转成UTF8编码。function ConverCode($str){ $encode = mb_d...

vscode运行php和Composer

vscode运行php和Composer

需要用到的工具1、安装php(官网下载)2、安装composer(官网)3、vscode插件PHP Server4、vscode插件PHP Debug5、windows 11系统步骤1、安装php安装...

php获取网站在服务器中用的环境

php获取网站在服务器中用的环境

判断当前网站在服务器用的什么环境function GetWebServer() {     if (!isset($_SERVER[&#...

php远程提交post函数

php远程提交post函数

远程提交方式:post范围:所有php类型程序函数代码function post($params, $url) {     $c...

php分割string并取某项数据

php分割string并取某项数据

对string进行分割,并取某项数据。应用案例$txt="姓名|电话|手机号|豫唐"; $name=SplitAndGet($txt,"|",3); ech...

php获取文件权限

php获取文件权限

获取文件的权限,权限格式分为数值格式(如0644)和字符表达格式(如-rw-r--r--)两种数值格式应用案例$url="1.txt"; $name=GetFilePermsOc...