1//php check if first four characters of a string = http
2substr( $http, 0, 4 ) === "http";
3//php check if first five characters of a string = https
4substr( $https, 0, 5 ) === "https";
5
1function stringStartsWith($haystack,$needle,$case=true) {
2 if ($case){
3 return strpos($haystack, $needle, 0) === 0;
4 }
5 return stripos($haystack, $needle, 0) === 0;
6}
7
8function stringEndsWith($haystack,$needle,$case=true) {
9 $expectedPosition = strlen($haystack) - strlen($needle);
10 if ($case){
11 return strrpos($haystack, $needle, 0) === $expectedPosition;
12 }
13 return strripos($haystack, $needle, 0) === $expectedPosition;
14}
15echo stringStartsWith("Hello World","Hell"); // true
16echo stringEndsWith("Hello World","World"); // true
1phpCopy<?php
2 $string = "mr. Peter";
3 if(strncasecmp($string, "Mr.", 3) === 0){
4 echo "The string starts with the desired substring.";
5 }else
6 echo "The string does not start with the desired substring.";
7?>
8