简体   繁体   English

使用正则表达式PHP获取两个定界符之间的所有字符串(子字符串)

[英]Get all strings between two delimiters (sub strings) with regex PHP

Can anybody help me with a function in php using regex to return all founded sub strings between two delimiters. 任何人都可以使用regex帮助我使用php中的函数来返回两个定界符之间所有已建立的子字符串。

expmple : 示例:

<p class="mn"><a href="123517/2882"> Hi all 5 </a>
<p class="mn"><a href="123518/2662"> Hi all 6 </a>
<p class="mn"><a href="123519/2552"> Hi all 55 </a>
<p class="mn"><a href="1235100/7722"> Hi all 15</a>

I need to get all substrings between <p class="mn"><a href=" and "> using regex php function. 我需要得到之间的所有子<p class="mn"><a href="">使用正则表达式PHP函数。

I tried some methods here but I can not handle regex syntax rightly, so I need a help with regex syntax and how to use it. 我在这里尝试了一些方法,但是我无法正确处理正则表达式语法,因此我需要有关正则表达式语法以及如何使用它的帮助。

thanks 谢谢

In the specific sense, try 在特定意义上,尝试

preg_match_all('@<p class="mn"><a href="(.+?)">@', $str, $m);

In the general sense, parse the HTML with a library and use XPath . 一般而言, 使用库解析HTML并使用XPath

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM