Stringy\Stringy::endsWith PHP Method

endsWith() public method

Returns true if the string ends with $substring, false otherwise. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.
public endsWith ( string $substring, boolean $caseSensitive = true ) : boolean
$substring string The substring to look for
$caseSensitive boolean Whether or not to enforce case-sensitivity
return boolean Whether or not $str ends with $substring
    public function endsWith($substring, $caseSensitive = true)
    {
        $substringLength = \mb_strlen($substring, $this->encoding);
        $strLength = $this->length();
        $endOfStr = \mb_substr($this->str, $strLength - $substringLength, $substringLength, $this->encoding);
        if (!$caseSensitive) {
            $substring = \mb_strtolower($substring, $this->encoding);
            $endOfStr = \mb_strtolower($endOfStr, $this->encoding);
        }
        return (string) $substring === $endOfStr;
    }

Usage Example

Esempio n. 1
2
 private function isAlbum()
 {
     if (!empty($this->parsedUrl['path'])) {
         // TODO: как правильно вызывать Stringy чтобы не создавать 100 экземпляров внутри кода?
         $stringy = new Stringy();
         $result = $stringy->endsWith(Urls::ALBUM);
         if ($result === true) {
             return true;
         }
     }
     return false;
 }