PHP Salt


A little dash of PHP... my collection of php functions

Version: 2.14.1
Last Build: March 10, 2017 13:28pm (PST)

psStrBeginsWithi()
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:


And a shot out to:

LinuxSimple - www.linuxsimple.com
PHP - php.net
Fedora Server - getfedora.com
Shameless ads to pay for site