-->

PHP资讯

您的当前位置:首页 > 资讯 > PHP基础

提取整片文章中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索引重置

测试数据

  1. <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"/>&nbsp;</p>

结果

  1. array (size=5)

  2.  0 =>

  3.    array (size=2)

  4.      0 => string 'src="/Shop/Upload/ueditor/20171221/1513806081642421.jpg' (length=55)

  5.      1 => string 'src="/Shop/Upload/ueditor/20171221/1513806089468745.jpg' (length=55)

  6.  1 =>

  7.    array (size=2)

  8.      0 => string 'src' (length=3)

  9.      1 => string 'src' (length=3)

  10.  2 =>

  11.    array (size=2)

  12.      0 => string '"' (length=1)

  13.      1 => string '"' (length=1)

  14.  3 =>

  15.    array (size=2)

  16.      0 => string '/Shop/Upload/ueditor/20171221/1513806081642421.jpg' (length=50)

  17.      1 => string '/Shop/Upload/ueditor/20171221/1513806089468745.jpg' (length=50)

  18.  4 =>

  19.    array (size=2)

  20.      0 => string 'jpg' (length=3)

  21.      1 => string 'jpg' (length=3)


相关文章更多 >

© 2024版权所有 水水网

电话:171780793