PDA

View Full Version : Pregmatch


rjlstar
09-17-2008, 07:34 PM
I have this string stored in $string:


<a href="google.com">google</a>
<a href="/submission/174583/hello/showmore,designs">a</a>
<a href="/submission/174584/world/showmore,designs">b</a>
<a href="/submission/174585/qbasic/showmore,designs">c</a>


It actually has no spaces. I just put in the line returns for readability.

How can I extract all the URL's which are under the folder "submission"?

I tried this, but it failed miserably:


preg_match('/submission\/([0-9]+)\//', $string, $match);


$match[0] contained "submission/174583"
$match[1] contained "174583"

BonRouge
09-17-2008, 08:40 PM
With or without the 'submission' bit?

Here's both:
//with
preg_match_all('/submission\/.*(?=")/', $string, $match);

//without
preg_match_all('/(?<=submission\/).*(?=")/', $string, $match);
The urls are in the $match[0] array.