PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Dec 07, 2019 1:27 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: preg_replace problem
PostPosted: Fri Jun 03, 2005 11:27 pm 
Offline
Forum Commoner

Joined: Fri May 13, 2005 2:36 pm
Posts: 32
Location: phoenix
i'd like to have:

Syntax: [ Download ] [ Hide ]
$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

Syntax: [ Download ] [ Hide ]
$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.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 04, 2005 5:43 am 
Offline
Breakbeat Nuttzer
User avatar

Joined: Wed Mar 24, 2004 8:57 am
Posts: 13098
Location: Melbourne, Australia


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 04, 2005 5:48 am 
Offline
Breakbeat Nuttzer
User avatar

Joined: Wed Mar 24, 2004 8:57 am
Posts: 13098
Location: Melbourne, Australia
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


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 04, 2005 2:35 pm 
Offline
Forum Regular
User avatar

Joined: Sat Mar 12, 2005 8:13 pm
Posts: 703
Location: US
Make it so right before the first can't be a " ' or =
Syntax: [ Download ] [ Hide ]
$body = preg_replace("`([^\"\'=])((http...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group