I am trying to resolve an issue I have been having with one of my wordpress plugins.
This is line 666
function isUrl($url)
{
return preg_match("^http://[-0-9a-z._]+.*$/i", trim( $url ));
}
What are your inputs on how I can resolve this warning? It’s quite irritating. I can’t figure it out and I’ve tried, researched everything!
/
is missing.preg_match('/pattern/',$string);
As it has been said in other answers, you have to use delimiters arround the regex. You have also the possibility to use another character than
/
to avoid escaping them:And you could use
w
that is shortcut of[a-zA-Z0-9_]
:Your regex needs a delimiter around it, e.g. /
This delimiter can be different characters but it must be the same before and after your regex. You could e.g. also do this
or
The advantage is, use a delimiter that you don’t have inside the regex. If you use / as delimiter and want to match “/” you have to escape it inside the regex ///, if you change the delimiter you could do #/# to match a “/”