This question already has an answer here:
- startsWith() and endsWith() functions in PHP 31 answers
I'm trying to check if a string starts with http
. How can I do this check?
$string1 = 'google.com';
$string2 = 'http://www.google.com';
</div>
This question already has an answer here:
I'm trying to check if a string starts with http
. How can I do this check?
$string1 = 'google.com';
$string2 = 'http://www.google.com';
</div>
Use the substr function to return a part of a string.
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 http-protocol.com.
substr( $string_n, 0, 7 ) === "http://"
And in general:
substr($string, 0, strlen($query)) === $query