Forum Moderators: coopster
Example:
$Contents = "some string with a link [somesite.com ]";
$NewContents = preg_replace("/\[url\](.+?)\[\/url\]/i","<a href=\"$1\">$1</a>",$Contents);
Hope this helps!
However, do you know how to check the actual link string for syntax, because if the link string includes "http://" it works great, but if the link string goes straight to "www.something.com" the link that is generated is just added to the local path.
It would be a lot better if the function could take this into account.
Any ideas?
$Contents = "some string with a link http://www.example.com and try also a www.example.com if you want, ok?";
$NewContents = preg_replace("/\[url\](http:\/\/)?(.+?)\[\/url\]/i","<a href=\"http://$2\">$2</a>",$Contents);
Note we are now using the second subpattern as well as forcing the
http://back into the replacement string.