Regular expression

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
pedroz
Forum Commoner
Posts: 99
Joined: Thu Nov 03, 2005 6:21 am

Regular expression

Post by pedroz »

Code: Select all

$link_text = 'Apply now';
								
$content = '<td align="right" class="apply">   <a href="http://domain.com?h=AJ&cm=Details_ApplyNow" onClick="ApplyNowClick(\'A7C6NP\');" title="Apply for this now!">Apply Now</a></td>';
				

$pattern = '|<a[^>]+>('.$link_text.')</[^>]+>|U';   
preg_match($pattern, $content, $output); 

				
$pattern = '/<[a]{1}(.*)?>(.*)<\/[a]{1}>/';  
$content = trim(preg_replace($pattern, '$1', $output[0])); 

... // then parse $content to get the href url

Is it possible to know what is wrong with the regular expression to get the href of this tag?
<td align="right" class="apply"> <a href="http://domain.com?h=AJ&cm=Details_ApplyNow" onClick="ApplyNowClick(\'A7C6NP\');" title="Apply for this now!">Apply Now</a></td>

Not getting anything in $output. I've this code working for a similar <a ..> tag.

Thanks!
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Regular expression

Post by twinedev »

What exactly are you trying to do? Can you give an example of the value of $content you are trying to obtain?

-Greg
Post Reply