blindlizard
Mar 25th, 2004, 05:56 PM
I am such a regex noob it is not even funny. I have found this function to covert BBcode to HTML, but I found a problem.
If I do this, then it makes the URL like it should and puts the words 'Other Text' after the link like you would exprect.[ url=http://blah.com]balh[/url] Other Text
'<a href="http://blah.com target="_blank">blah</a> Other text"
If I do this, the 2 links get merged together.
[ url=http://blah.com]balh[/url] Other Text [ url=http://blah2.com]blah2[/url]
'<a href="http://blah.com" target="_blank">balh[/url] Other text [ url=http://blah2.com]blah2</a>
Here is my code to do the regex stuff
$texte = preg_replace('/\[url=(.+?)\](.+)\[\/url\]/i','<a href="\\1" target="_blank">\\2</a>',$texte);
**edit, I had to add the space between [ and url because vbforums was making it a link :)
Crap, it messes up my preg_replace stuff too.
If I do this, then it makes the URL like it should and puts the words 'Other Text' after the link like you would exprect.[ url=http://blah.com]balh[/url] Other Text
'<a href="http://blah.com target="_blank">blah</a> Other text"
If I do this, the 2 links get merged together.
[ url=http://blah.com]balh[/url] Other Text [ url=http://blah2.com]blah2[/url]
'<a href="http://blah.com" target="_blank">balh[/url] Other text [ url=http://blah2.com]blah2</a>
Here is my code to do the regex stuff
$texte = preg_replace('/\[url=(.+?)\](.+)\[\/url\]/i','<a href="\\1" target="_blank">\\2</a>',$texte);
**edit, I had to add the space between [ and url because vbforums was making it a link :)
Crap, it messes up my preg_replace stuff too.