正则表达式在PHP中搜索多个匹配项

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了正则表达式在PHP中搜索多个匹配项相关的知识,希望对你有一定的参考价值。

This will search for specific type of tag in html doc and extract type attribute value and all attributes after it in tag.
  1. $data = '<html>
  2.  
  3. <body>
  4. <jdoc:include type="head" name="popup" style="raw" />
  5.  
  6. <jdoc:include type="modules" name="dochead" style="raw" />
  7.  
  8. </body>
  9.  
  10. </html>';
  11.  
  12. if(preg_match_all('#<jdoc:include\ type="([^"]+)" (.*)\/>#iU', $data, $matches))
  13. {
  14. Will return
  15. $matches =
  16. [0][0] = "<jdoc:include type="head" name="popup" style="raw" />"
  17. [0][1] = "<jdoc:include type="modules" name="dochead" style="raw" />"
  18.  
  19. [1][0] = head
  20. [1][1] = modules
  21.  
  22. [2][0] = name="popup" style="raw"
  23. [2][1] = name="dochead" style="raw"
  24. }

以上是关于正则表达式在PHP中搜索多个匹配项的主要内容,如果未能解决你的问题,请参考以下文章