preg_replace problem

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

Moderator: General Moderators

Post Reply
jrucifer
Forum Commoner
Posts: 32
Joined: Fri May 13, 2005 2:36 pm
Location: phoenix

preg_replace problem

Post by jrucifer »

i'd like to have:

Code: Select all

$body = preg_replace("`((http)+(s)?:(//)|(www\.))((\w|\.|\-|_)+)(/)?(\S+)?`i", "<a href=\"http$3://$5$6$8$9\" target=\"blank\" title=\"$0\">$5$6</a>", $body);
to replace URLs that are typed in

and

Code: Select all

$body = preg_replace("|\[link=[\"\']?(.+?)[\"\']?\](.+?)\[/link\]|i", "<a href=\"http://www.$1\" target=\"blank\">$2</a>", $body);
so that they can have the link appear as text...

however, when the 2nd function is used, the URL that is submitted gets replaced by the first function. not sure if i explained that right, but i hope you will figure it out.

so, what do i need to do in order to use both without any conflicts? I promise I tried to figure it out myself before running here :roll:

thanks for any help.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

:arrow: Moved to regex
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

You're regex are crazy :? :D

Could you post some examples of strings that you want to convert?

i.e. If I have www.google.com I need to end up with [link=http://wwww.google.com]www.google.com[/link]

But at least 3 examples so we know where we're going :P
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

Make it so right before the first can't be a " ' or =

Code: Select all

$body = preg_replace("`([^\"\'=])((http...
Post Reply