Ok, I have been using a simple preg_replace() call in my forums to do most things, but just realized that my URLs were not working properly. DOH!
Could someone look at my patterns and let me know what I am doing wrong? I have isolated that pertinent code.
Basically, I would like people to be able to use:
1) [ url ]http://www.google.com[ / url ]
OR to make a simple text link as such:
2) [ url=http://www.google.com ]Google![ /url ]
Thanks for your help!
<?php
//regex replacement
$bbcode = array('`\[url=([a-z0-9]+://)([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\](.*?)\[/url\]`si',
'`\[url\]([a-z0-9]+?://){1}([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)\[/url\]`si',
'`\[url\]((www|ftp)\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\[/url\]`si'
);
$html = array('<a href="\1\2">\6</a>',
'<a href="\1\2">\1\2</a>',
'<a href="http://\1">\1</a>'
);
$string = preg_replace($bbcode, $html, $string);
?>