...

View Full Version : Search and replace in strings?



Priapulidae
01-08-2004, 01:08 PM
Hello!

I would like to fetch a database entry's text with php and search it after a string with certain markers around it, for example %, so that PHP can remake it to a hyperlink to another place with the words enclosed inside the %:s in the link, when all the text is outputted in the browser.

Basically I need a clue as to what function can accomplish this so I can look in to how to do it exaclty, cause right now I don't have a clue ;)

Very thankful for help!

/Magnus

Jeewhizz
01-08-2004, 07:20 PM
Hey there,

Your best bet is to surround it with something a little more unique, sure as something like this:



<url=>http://www.codingforum.com</url=>CodingForums</url>


You could then do a search/replace using something like str_replace() (which convenientlysupports arrays too ;)) like so:


$string = str_replace('<url=>','<a href="',$string);
$string = str_replace('</url=>','">',$string);
$string = str_replace('</url>','</a>',$string);

This is more or a PHP question, so i'll move it over there for you :)

Jee

Spookster
01-08-2004, 07:43 PM
The first thing you need to do is read our posting guidelines section 2

http://www.codingforums.com/postguide.htm

Priapulidae
01-08-2004, 08:36 PM
Thanks alot Jeewhizz! str_replace() seems to be the kind of thing I'm looking for.

I changed the subject to a hopefully more descriptive one, since I didn't know what I was lookin for I had a hard time naming the post :P



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum