note 114784 deleted from function.substr by cmb
| From: | cmb@php.net | Date: | Sun, 27 Oct 2019 09:09:41 +0000 |
| Subject: | note 114784 deleted from function.substr by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212830@lists.php.net to get a copy of this message | ||
Note Submitter: php at richardneill dot org
----
Frequently we want to check whether one string ends with (or starts with) another. These may be
useful:
function str_ends($string,$end){
return (substr($string,-strlen($end),strlen($end)) === $end);
}
function str_begins($string,$start){
return (substr($string,0,strlen($start)) === $start);
}
Example:
if (str_ends ($filename, ".jpg")){
echo "The extension is .jpg";
}