Page 1 of 1

preg_replace problem

Posted: Fri Jun 03, 2005 11:27 pm
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.

Posted: Sat Jun 04, 2005 5:43 am
by Chris Corbyn
:arrow: Moved to regex

Posted: Sat Jun 04, 2005 5:48 am
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

Posted: Sat Jun 04, 2005 2:35 pm
by Skara
Make it so right before the first can't be a " ' or =

Code: Select all

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