psStrBeginsWith() Determine if a string begins with a specific substring
Description:
You can use this to find out if a string begins with something specific.
Usage:
$bool = psStrBeginsWith($needle,$haystack); $bool = psStrBeginsWithi($needle,$haystack); // case insensitive
Example:
if ( psStrBeginsWith("PR_","PR_TEST") == true ) { // do something }
Code:
function psStrBeginsWith($needle,$haystack) { $res = false; $l = strlen($needle); if (substr($haystack,0,$l) == $needle) { $res = true; }
return $res; }
function psStrBeginsWithi($needle,$haystack) { $res = false; $l = strlen($needle); if (substr(strtolower($haystack),0,$l) == strtolower($needle)) { $res = true; }
return $res; }
Changlelog:
|
|