欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP正則匹配操作簡單示例【preg_match_all應(yīng)用】

 更新時間:2017年07月10日 09:59:35   作者:a771948524  
這篇文章主要介紹了PHP正則匹配操作,結(jié)合簡單實例形式分析了php中preg_match_all針對HTML標(biāo)簽中P元素及img src元素內(nèi)容的獲取技巧,需要的朋友可以參考下

本文實例講述了PHP正則匹配操作。分享給大家供大家參考,具體如下:

<?php
$str = <<< EOT
        <a href="www/app/a/2QRN7v" rel="external nofollow" >
          <div class="phonebg">
            <img src="http://www/template9/yunqingjian/jianjie/68.jpg" >
            <div class="phoneclick"></div>
            <p>幸福領(lǐng)地</p>
          </div>
        </a>
        <a href="www/app/a/uqARNv" rel="external nofollow" >
          <div class="phonebg">
            <img src="http://www/template9/yunqingjian/jianjie/69.jpg" >
            <div class="phoneclick"></div>
            <p>一世情長</p>
          </div>
        </a>
EOT;
if(preg_match_all('%<p.*?>(.*?)</p>%si', $str, $matches)) {
  $arr[0][] = $matches[1];
}
if(preg_match_all('/src="([^<]*)" >/i', $str, $matches)) {
  $arr[1][] = $matches[1];
}
print_r($arr);
exit;
?>

運行結(jié)果如下:

Array
(
  [0] => Array
    (
      [0] => Array
        (
          [0] => 幸福領(lǐng)地
          [1] => 一世情長
        )
    )
  [1] => Array
    (
      [0] => Array
        (
          [0] => http://www/template9/yunqingjian/jianjie/68.jpg
          [1] => http://www/template9/yunqingjian/jianjie/69.jpg
        )
    )
)

PS:這里再為大家提供2款非常方便的正則表達(dá)式工具供大家參考使用:

JavaScript正則表達(dá)式在線測試工具:
http://tools.jb51.net/regex/javascript

正則表達(dá)式在線生成工具:
http://tools.jb51.net/regex/create_reg

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php正則表達(dá)式用法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP基本語法入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家PHP程序設(shè)計有所幫助。

相關(guān)文章

最新評論