4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 PHP: Multiple eregi_replace/preg_replace: help
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
jayant
Team Member



Joined: 07 Jan 2002
Posts: 262
Location: New Delhi, India

PostPosted: Thu Mar 06, 2003 9:23 am (21 years, 1 month ago) Reply with QuoteBack to Top

if "abc" and "abc def" have to be linked with URL1 and URL2
then in the text:
"kjkhj abc lkjhsdf abc def ljh"
I want the output as
"kjkhj <a href=URL1>abc</a> lkjhsdf <a href=URL2>abc def</a> ljh"
instead of
"kjkhj <a href=URL1>abc</a> lkjhsdf <a href=URL2><a href=URL1>abc</a> def</a> ljh"
or
"kjkhj <a href=URL1>abc</a> lkjhsdf <a href=URL1>abc</a> def ljh"

How can I achieve this ?

Thanks in advance.
Prize: A BMW to the one who answers this correctly Wink

________________________________
Jayant Kumar
Member of the 4WebHelp Team
Nibble Guru - Computing Queries Demystified
GZip/ Page Compression Test
OfflineView User's ProfileFind all posts by jayantSend Personal MessageVisit Poster's WebsiteYahoo MessengerMSN Messenger
drathbun
WebHelper
WebHelper


Joined: 01 Mar 2003
Posts: 69
Location: Texas

PostPosted: Thu Mar 06, 2003 3:20 pm (21 years, 1 month ago) Reply with QuoteBack to Top

Here's what I would do...

Do the longer ones first, replacing the token "abc def" with some other value on a temporary basis. Then work your way down to the shorter ones. When you're done putting in the code to turn the item into a URL, replace the token strings with the original content.

In other words, sort your replacement strings by length:
abc def
abc

Next, replace abc def with ##TOKEN01##, and replace abc with ##TOKEN02##. You could use an array, where the original code is the index, as in
Code:
tokens['abc def'] = '##TOKEN01##'
tokens['abc'] = '##TOKEN02##'


Build your urls, and then replace every token with it's original language.

Since it's not the actual code, just an idea, I'll accept a picture of a BMW instead. Wink

Dave

________________________________
Dave
Photography Site :: Query Tools Forum :: Weekend Fun
OfflineView User's ProfileFind all posts by drathbunSend Personal MessageVisit Poster's Website
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   




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 vote in polls in this forum.


Page generation time: 0.135976 seconds :: 19 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme