Your regex needs a delimiter around it, for example. /
return preg_match("/^http:\/\/[-0-9a-z\._]+.*$/i", trim( $url ));
This delimiter can be different characters, but it must be the same before and after your regular expression. You can, for example, also do this.
~regex~
or
#regex
The advantage is to use a delimiter that does not exist inside the regular expression. If you use / as a delimiter and want to match "/", you need to avoid it inside the regular expression ///, if you change the delimiter, you can do # / # to match "/"
source share