REGEX formula.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wren9
Forum Newbie
Posts: 9
Joined: Sat May 23, 2009 1:50 am

REGEX formula.

Post by wren9 »

Hi i know this is very simple for REGEX old timer.

I have this link below,

Code: Select all

 
<a href="http://domain.org/tlg/1188777994.html">MANAGER NEEDED</a>
 
All i want is to get the text "MANAGER NEEDED" from that link.

I've been formulating for hours now and i'm completely lost i guess.

Anyone would to show the REGEX for this?

thanks in advance.
Last edited by Benjamin on Tue May 26, 2009 10:53 am, edited 1 time in total.
Reason: Changed code type from text to html.
wren9
Forum Newbie
Posts: 9
Joined: Sat May 23, 2009 1:50 am

Re: REGEX formula.

Post by wren9 »

Also how about i want to get the content of href which is "http://domain.org/tlg/1188777994.html" ?

Thanks again in advance.
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: REGEX formula.

Post by prometheuzz »

Try something like this:

Code: Select all

preg_match(
  '#<a\s+href="([^"]+)"\s*>([^<]+)</a>#i', 
  '<a href="http://domain.org/tlg/1188777994.html">MANAGER NEEDED</a>', 
  $result
);
 
print_r($result);
/*
Array
(
    [0] => <a href="http://domain.org/tlg/1188777994.html">MANAGER NEEDED</a>
    [1] => http://domain.org/tlg/1188777994.html
    [2] => MANAGER NEEDED
)
*/
Post Reply