I have a regex that takes a string like a bbcode and transforms it to a html link. It work fine. but, I want to make it detect the type of the link (internal/external) to decide whether to strictly use the absolute (external) url like http://extsite.com/category/keyword/ or use the part of the internal url like category/keyword/ and append it to a predefined url like $url . category/keyword/
The regex is as follows:
preg_replace('/\[([^\]]+)\]\[([^\]"]+)\]/i', '<a href="$2">$1</a>', $text)
Any suggestion will be very appreciated.
Based on your comment, I will assume that any link that starts with http:// (or any similar protocol, e.g. ftp://) is an absolute link. Any other link will be considered a relative link (and will be prefixed by $url)