Replace this, but not between these...

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

Moderator: General Moderators

Post Reply
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Replace this, but not between these...

Post by Grim... »

Here is the code I have that turns URL's into hyperlinks:

Code: Select all

$text = ereg_replace("[a-zA-Z]+://([.]?[a-zA-Z0-9_/?:+=&-])*", "<a href=\"\\0\">\\0</a>", $text);
$text = ereg_replace("(^| )(www([.]?[a-zA-Z0-9_/?:+=&-])*)", "\\1<a href=\"http://\\2\">\\2</a>", $text);
The thing is, I don't want this to happen if the URL is inside tags, for obvious reasons.

Is this possible?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

have you looked through phpbb's bbcode.php file?
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

No, but I will.

I suspect, however, that my reaction will be something like 8O
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

8O
CallumD
Forum Newbie
Posts: 11
Joined: Wed May 03, 2006 12:36 am

Post by CallumD »

:D
Post Reply