tags:

views:

28

answers:

2

I have the following string for example:

Welcome to my <a href="http://example.com"&gt;site&lt;/a&gt;. Feel free to  <a href="http://localhost.com"&gt;contact me</a>.

What technique may I use to evaluate this string to add '/id/123' at the end of both of the urls resulting in:

Welcome to my <a href="http://example.com/id/123"&gt;site&lt;/a&gt;. Feel free to  <a href="http://localhost.com/id/123"&gt;contact me</a>.

Thanks.

+2  A: 

This should work:

$string = preg_replace('/href="([^"]*)"/','href="\\1/id/123"',$string);

Oh thank you, I didn't expect the full solution. Thanks!
synonymsynonyms
A: 
$result = preg_replace('/<a\s+href="([^"]+)"/', '<a href="\1/id/123"', $subject);
Tim Pietzcker