Page 1 of 1

Regular expression

Posted: Wed Sep 28, 2011 8:27 am
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!

Re: Regular expression

Posted: Wed Sep 28, 2011 9:25 am
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