You are currently using the forward slash (/
) as the delimiter, but you aren't escaping it inside your pattern string. This will result in an error and will cause your preg_match()
statement to not work (if you don't have error reporting enabled).
Also, you are using alternation incorrectly. If you want to match either foo
or bar
, you'd write (foo|bar)
, and not {foo|bar}
.
The updated preg_match()
should look like:
preg_match("/^(http|ftp|https):\/\/localhost.*/", $url)
Or with a different delimiter (so you don't have to escape all the /
characters):
preg_match("#^(http|ftp|https)://localhost.*#", $url)