parse error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

parse error

Post 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
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

ah, i see the error now, thanks to the boards syntax highlighting =]
sorry.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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;
}
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply