Andrew Andrew - 1 year ago 92
PHP Question

How to check if a string starts with a specified string?

I'm trying to check if a string starts with

. How can I do this check?

$string1 = '';
$string2 = '';

Answer Source
substr( $string_n, 0, 4 ) === "http"

If you're trying to make sure it's not another protocol. I'd use http:// instead, since https would also match, and other things such as

substr( $string_n, 0, 7 ) === "http://"

And in general:

substr($string, 0, strlen($query)) === $query
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download