Skip to content

Latest commit

 

History

History
21 lines (15 loc) · 534 Bytes

ends-with.md

File metadata and controls

21 lines (15 loc) · 534 Bytes
标题 标签
ends-with(匹配字符串结尾) string,beginner(字符串,初学者)

检查字符串是否以给定的子字符串结尾。

  • 将 strrpos() 与 strlen 结合使用,查找 $str 中 $end 的位置。

代码如下:

function endsWith($str,$end){
    return strrpos($str,$end) === strlen($str) - strlen($end);
}

使用方式:

endsWith('Hi, this is me', 'me'); // true