Welcome to WebmasterWorld Guest from 54.226.241.8

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Need regEx to extract string between anchor tags in PHP

preg-match, PHP

     

iamvela

9:14 am on Jul 15, 2008 (gmt 0)

5+ Year Member



I am trying to extract text between
Reply to: <a ..............>*</a>
i.e. I want the value of *


I tried
if (0 < preg_match("/^Reply to: \<a.\>(.)+</a>/", $page, $matches))
{
echo $matches[1] . "<br>" ;
echo $matches[2] . "<br>" ;
}
else
echo "Pattern not matched <br>" ;

and this
if (0 < preg_match("<a\b[^>]*>(.*?)</a>", $page, $matches))
{
echo $matches[1] . "<br>" ;
echo $matches[2] . "<br>" ;
}
else
echo "Pattern not matched <br>" ;

neither worked.

I'd really appreciate any help, THANKS!

adb64

9:37 am on Jul 15, 2008 (gmt 0)

10+ Year Member



Try: preg_match [php.net]("#Reply to: <a.+>(.+)</a>#U",$page,$matches)
The U modifier makes it ungreedy and using a # as delimiter instead of / which clashes with the / in </a>
There are several online regex testers available, Google for 'online regular expression tester' and you will find several.

iamvela

5:52 pm on Jul 15, 2008 (gmt 0)

5+ Year Member



Thanks sooooooooooo much!

I did try testers before posting this, but am weak on the writing regex. As you can see I was very close, but as they say "close, but no cigar" :)

Again thanks a bunch for your help!

 

Featured Threads

Hot Threads This Week

Hot Threads This Month