php正则提取img所有属性值,php提取img属性值_PHP教程

WBOY
發布: 2016-07-12 09:07:44
原創
1024 人瀏覽過

php正则提取img所有属性值,php提取img属性值

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

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1059462.htmlTechArticlephp正则提取img所有属性值,php提取img属性值 $ext = 'gif|jpg|jpeg|bmp|png'; // 罗列图片后缀从而实现多扩展名匹配 by http://www.k686.com 绿色软件 $st...
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!