I want to convert [url]http://www.stackoverflow.com[/url]
to:
<a href="http://www.stackoverflow.com">http://www.stackoverflow.com</a>
I assume that I want to use preg_replace()
, but I just can't get it working.
$str = preg_replace('/\[url\](.*?)\[\/url\]/', '<a href="$1">$1</a>', $str);
PHP does have a BBCode parser too.
BBCode sucks... have you tried Markdown?