Welcome to WebmasterWorld Guest from 54.204.129.35

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Need regEx to extract string between anchor tags in PHP

preg-match, PHP

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

Junior Member

5+ Year Member

joined:July 11, 2008
posts: 88
votes: 0


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!

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

Full Member

10+ Year Member

joined:Feb 4, 2004
posts:305
votes: 0


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.
5:52 pm on July 15, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:July 11, 2008
posts:88
votes: 0


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!

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members