jacek wrote:This is an archive post, any discussion should take place here viewtopic.php?f=5&t=8
These are three functions from my standard php library. they tend to be pretty useful as I get sick of having to constantly look up the order of parameters for strpos
[syntax=php]function str_starts_with($needle, $haystack){
$needle_len = strlen($needle);
return ($needle_len <= strlen($haystack) && substr($haystack, 0, $needle_len) === $needle);
}
function str_ends_with($needle, $haystack){
$needle_len = strlen($needle);
return ($needle_len <= strlen($haystack) && substr($haystack, -$needle_len) === $needle);
}
function str_contains($needle, $haystack){
return (strpos($haystack, $needle) !== false);
}[/syntax]
fairly self explanatory really.