提取整片文章中img的src属性,并保存到一个数组当中
2022-09-28 14:53:16 来源:admin 点击:532
需求:提取整片文章中img的src属性,并保存到一个数组当中
preg_match_all("/(href|src)=([\"|']?)([^\"'>]+.(jpg|JPG|jpeg|JPEG|gif|GIF|png|PNG))/i", $content,$out,PREG_PATTERN_ORDER);
$preg = "/(href|src)=([\"|']?)([^\"'>]+.(jpg|JPG|jpeg|JPEG|gif|GIF|png|PNG))/i";
preg_match_all($preg, $content, $matchs ,PREG_PATTERN_ORDER);//PREG_PATTERN_ORDER索引重置
测试数据
<p>
<img src="/Shop/Upload/ueditor/20171221/1513806081642421.jpg" title="1513806081642421.jpg" alt="Desert.jpg"/></p><p>
<img src="/Shop/Upload/ueditor/20171221/1513806089468745.jpg" title="1513806089468745.jpg" alt="Chrysanthemum.jpg"/> </p>
结果
array (size=5)
0 =>
array (size=2)
0 => string 'src="/Shop/Upload/ueditor/20171221/1513806081642421.jpg' (length=55)
1 => string 'src="/Shop/Upload/ueditor/20171221/1513806089468745.jpg' (length=55)
1 =>
array (size=2)
0 => string 'src' (length=3)
1 => string 'src' (length=3)
2 =>
array (size=2)
0 => string '"' (length=1)
1 => string '"' (length=1)
3 =>
array (size=2)
0 => string '/Shop/Upload/ueditor/20171221/1513806081642421.jpg' (length=50)
1 => string '/Shop/Upload/ueditor/20171221/1513806089468745.jpg' (length=50)
4 =>
array (size=2)
0 => string 'jpg' (length=3)
1 => string 'jpg' (length=3)