PHP中的startsWith()和endsWith()函数

问题:

How can I write two functions that would take a string and return if it starts with the specified character/string or ends with it? 我如何编写两个带字符串的函数,如果它以指定的字符/字符串开头或以它结尾,则返回?

For example: 例如:

$str = '|apples}';

echo startsWith($str, '|'); //Returns true
echo endsWith($str, '}'); //Returns true

解决方案:

参考一: https://stackoom.com/question/3V2V/PHP中的startsWith-和endsWith-函数
参考二: https://oldbug.net/q/3V2V/startsWith-and-endsWith-functions-in-PHP

评论

暂无评论