OK. So I am building a function that will parse a bbcoded string to html. The structure of the BBCode link is like so:
[url=http://somelink.com/]Link[/url]
And I want to make it:
<a href="http://somelink.com/">Link</a>
But I also want to check if the link is valid, to protect myself from XSS. I found this regex to check for valid link:
/(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
And now, I tried to preg_match_all the $str and foreach match to check if it's url is valid and then to parse it to html, but it seems that I can't do it. Any suggestions?