user504363
user504363

Reputation: 551

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.

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.

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

Upvotes: 1

Views: 1987

Answers (1)

Rusty Fausak
Rusty Fausak

Reputation: 7525

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.

Upvotes: 5

Related Questions