Page 1 of 1

parse error

Posted: Tue Mar 07, 2006 5:45 am
by s.dot
I don't understand this parse error:

Code: Select all

function reverseURLTags($text){
	if(preg_match("#<a href=\"(.+?)\" target=\"_blank\">(.+?)</a>#im,$text,$rurls)){
		return str_replace($rurls[0],"[url={$rurls[1]}]{$rurls[2]}[/url]",$text);
	}
}
It says 'unexpected '[' on line 258' -- the str_replace line

Posted: Tue Mar 07, 2006 5:46 am
by s.dot
ah, i see the error now, thanks to the boards syntax highlighting =]
sorry.

Posted: Tue Mar 07, 2006 6:25 am
by s.dot
on a side note, anyone looking to perhaps used that function should use preg_match_all (instead of preg_match) and then loop through the array and str_replace()

Code: Select all

function reverseURLTags($text){
	if(preg_match_all("#<a href=\"(.+?)\" target=\"_blank\">(.+?)</a>#im",$text,$rurls)){
		$i=0;
		foreach($rurls[0] AS $url){
			$text = str_replace($url,"[url={$rurls[1][$i]}]{$rurls[2][$i]}[/url]",$text);
			$i++;
		}
	}
	return $text;
}