Home >Backend Development >PHP Tutorial >php正则提取img所有属性值

php正则提取img所有属性值

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 13:25:03968browse

$ext = 'gif|jpg|jpeg|bmp|png';//罗列图片后缀从而实现多扩展名匹配 by http://www.k686.com 绿色软件  $str = '';    $list = array();    //这里存放结果map  $c1 = preg_match_all('/php正则提取img所有属性值/', $str, $m1);  //先取出所有img标签文本  for($i=0; $i<$c1; $i++) {    //对所有的img标签进行取属性      $c2 = preg_match_all('/(\w+)\s*=\s*(?:(?:(["\'])(.*?)(?=\2))|([^\/\s]*))/', $m1[0][$i], $m2);   //匹配出所有的属性      for($j=0; $j<$c2; $j++) {    //将匹配完的结果进行结构重组          $list[$i][$m2[1][$j]] = !empty($m2[4][$j]) ? $m2[4][$j] : $m2[3][$j];      }  }  print_r($list); //查看结果变量

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn