PHP 正則匹配html的標籤

網上的解決方案只能匹配的 png jpg gif等後綴的img標籤,可是如今微信的文章等網站 是經過js標籤等,img格式裏面的url是沒有.jpg等後綴的,因此網上搜索到的一些解決方案就再也不試用,因此本身現學現賣造了個新的輪子,能夠解決PHP 正則匹配html的<img>標籤的狀況 代碼以下: php

$pattern_src = '/<img[\s\S]*?src\s*=\s*[\"|\'](.*?)[\"|\'][\s\S]*?>/';

  

<?php$pattern_src = '/<img[\s\S]*?src\s*=\s*[\"|\'](.*?)[\"|\'][\s\S]*?>/';
$data = '<img data-s="300,640" data-src="http://mmbiz.qpic.cn/mmbiz/PY7Tb9FwY4A/0" data-w="360" src="http://mmbiz.qpic.cn/mmbiz/PY74A/640?tp=webp&wxfrom=5" style="width: height: auto !important;">';
// $num1 = preg_match_all($pattern_src, $data, $match_src1);
$urlContent=file_get_contents("http://mp.weixin.qq.com/s?__biz=MjM5NzQzOTgyMA==&mid=203551171&idx=1&sn=e92961eed85cf07f3937fd18a9e157a8#rd");
// echo  $urlContent;
$num1 = preg_match_all($pattern_src, $urlContent, $match_src1);
$arr_src1 = $match_src1[1];
var_dump($arr_src1);
echo "結束";
?>
相關文章
相關標籤/搜索