PHP is a very popular language for the development of Web sites. In our opinion, however, PHP has several gaps, including the lack of some strings comparison functions.
Here are the three useful functions that, in our view, are missing and how to implement them.
How to check if a string contains another string.
<?php function contains($subject, $find) { return (strpos($subject, $find) !== false); }
How to check if a string starts with another string.
<?php function startsWith($subject, $find) { $f = substr($subject, 0, strlen($find)); return ($f == $find); }
How to check if a string ends with another string.
<?php function endsWith($subject, $find) { $f = substr($subject, strlen($find) * -1); return ($f == $find); }