Hi there,
just a quick one really, tried searching the forum and no luck, so here goes...
i want to make it easy to add hyperlinks to text that is added to a database, for example:
click here[/ur] How can i convert that into a html hyperlink? ive sorted my bold, underline etc with a reg_replace and an expression (by searching forum), any1 know how to do the same with this? Thanks Jonathan
this should work.
$string = "text text text [url=http://www.yoursite.com]yoursite[/ur l] more text"; $url = preg_replace("/\[url=(.*)\](.*)\[\/url\]/", "<a href=\"\${1}\">\${2}</a>", $string);
here's a bit of code that will cover all 3 types of url's: http://www.site.com [url]http://www.site.com[/ur l] title[/ur l] where $string is your posted textbox.
$patterns = array("/\[url\](.*)\[\/url\]/", "/\s(f|ht)(tps?:\/\/)(\S*)/", "/\[url=(.*)\](.*)\[\/url\]/"); $replaces = array("<a href=\"\\1\">\\1</a>", " <a href=\"\\1\\2\\3\">\\1\\2\\3</a>", "<a href=\"\\1\">\\2</a>"); $string = preg_replace($patterns, $replaces, $string);
thanks for that mate, works a treat 🙂