Find and Unlink URLs

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
kirk7880
Forum Newbie
Posts: 3
Joined: Wed Feb 08, 2006 3:32 pm

Find and Unlink URLs

Post by kirk7880 »

I used str_replace to rewrite a few urls, however, certain url parameters contain similar names as "a href" parameter.

To be clear the url have "title" in the param.... as you know, href's tags sometimes contain (a href=domain title=xxx>)

I only rewrote a portion of the url

http://www.xxx.com/xxx.php?search=xxx&title=xxx

$buffer = str_replace("&title=", "/title/", $buffer);

The problem is that this rewrite's the title tag in the hyperlinks. (from <a href=xxx title=xxx> to <a href=xxx title/xxx>)

How can i write this rule so the "<a href" title tag is not affected?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Fiddly. Negative Lookbehind perhaps?

Code: Select all

echo preg_replace('/(?<!\s)title=/i', 'title/', $link);
Post Reply