Hello, I'm trying to do a bbcode parser class that can create personalyzed tags, but I have some problem with urls
I've did all I need without particular problems thanks to regular expressions but I have a problem when I try to create a special tag who point to a specified URL.
In my class I've added a method like this:
<?
private function check_url_from_bbcode ($tag = "url", $css = null, $url_path = null) {
$regex_url = " a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'";
if (!isset ($css)) $css = $this->css_link;
$regex_url = $this->regex_url;
if (isset ($url_path)) $url_path = "$url_path/";
$this->bbcode = preg_replace ("/\[$tag\]([$regex_url]*)\[\/$tag\]/", "<a title=\"Vai al link\" class=\"$css\" href=\"$url_path$1\">$1</a>", $this->bbcode);
$this->bbcode = preg_replace ("(\[$tag\=([$regex_url]*)\](.+?)\[/$tag\])", "<a title=\"Vai al link\" class=\"$css\" href=\"$url_path$1\">$2</a>", $this->bbcode);
}
?>
the code works fine with classical urls [url]http://ciao.com%5B/url%5D & [url=http://ciao.com%5Dciao%5B/url%5D
but I have some problem with the case of a special url subject page as last.fm style, so [artist]Lemon Jelly[/artist].
The bblink is converted in < a href="http://ciao.com/artist/Lemon Jelly">Lemon Jelly< /a> (I've used the spaces < a> only to show the link code).
The link has the whitespaces on the href attribute so can't never work.
<?
private function check_url_from_bbcode ($tag = "url", $css = null, $url_path = null) {
$regex_url = " a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'";
if (!isset ($css)) $css = $this->css_link;
$regex_url = $this->regex_url;
if (isset ($url_path)) $url_path = "$url_path/";
// begin of the problem
$this->bbcode = preg_replace ("/\[$tag\]([$regex_url]*)\[\/$tag\]/", "<a title=\"Vai al link\" class=\"$css\" href=\"$url_path".str_replace (" ", "+", $1)."\">$1</a>", $this->bbcode);
// end of the problem
$this->bbcode = preg_replace ("(\[$tag\=([$regex_url]*)\](.+?)\[/$tag\])", "<a title=\"Vai al link\" class=\"$css\" href=\"$url_path$1\">$2</a>", $this->bbcode);
}
?>
To avoid this, I've wrote a little part of code that change the href url portion with tha same url but with "+" in place of " " whitespace char, so [artist]Lemon Jelly[/artist] should became < a href="http://ciao.com/artist/Lemon+Jelly">Lemon Jelly< /a>
I'm not experienced with PHP and I'm not sure what is the problem, I've uses this syntax in other situation without encounter the problem.
can someone help me to find where I'm wrong?
the error type is PHP Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in /...