PDA

View Full Version : String search and replace


Ryltar
12-20-2004, 03:45 PM
Hello, I am trying to create a wiki like page but am having a few problems.
I am trying to use str_replace() (or something similar) to change www.google.com to the actual html formatting when the page is viewed. I know the format to search out specific strings or bits of strings, but I just can't seem to figure out how to find out what is between a set of tags... Any help would be appriciated, thanks!

Ryltar
12-20-2004, 04:30 PM
strike that. Finally figured out a roundabout way of doign this.

function translateContents( $text ) {
$text = preg_replace ( "/\n/i", "<br />", $text );//Replaces lines endings with breaks

$result = preg_replace ( "/.+\[link\]/i", "", $text );
$result = preg_replace ( "/\[\/link\].+/i", "", $result );
$result = preg_replace ( "/\[link\].+\[\/link\].+/i", "<a href = 'http://$result'>$result</a>", $text );

return $result;

}

I know it is kind of ungainly, but it works.