Notepad++Good Luck To You!

php 检查字符串是否以指定的字符开头或结尾
/**
* 检查字符串是否以某个字符串开头
* @param string $haystack 被检查的字符串
* @param string $needles 需要包含的字符串
* @param bool $strict 为true 则检查时区分大小写
*/
function startsWith($haystack, $needles, $strict = true)
{
// 不区分大小写的情况下 全部转为小写
   if (!$strict) $haystack = mb_strtolower($haystack);

// 支持以数组方式传入 needles 检查多个字符串
   foreach ((array)$needles as $needle) {
       if (!$strict) $needle = mb_strtolower($needle);
       if ($needle != '' && mb_strpos($haystack, $needle) === 0) {
           return true;
       }
   }
   return false;
}

/**
* 检查字符串是否以某个字符串结尾
* @param string $haystack 被检查的字符串
* @param string $needles 需要包含的字符串
* @param bool $strict 为true 则检查时区分大小写
*/
function endsWith($haystack, $needles, $strict = true)
{
// 不区分大小写的情况下 全部转为小写
   if (!$strict) $haystack = mb_strtolower($haystack);

// 支持以数组方式传入 needles 检查多个字符串
   foreach ((array)$needles as $needle) {
       if (!$strict) $needle = mb_strtolower($needle);
       if ((string)$needle === mb_substr($haystack, -mb_strlen($needle))) {
           return true;
       }
   }
   return false;
}


«    2023年7月    »
12
3456789
10111213141516
17181920212223
24252627282930
31
TOP 搜索
TOP 控制面板
您好,欢迎到访网站!
  查看权限
TOP 最新留言
    TOP 作者列表
    TOP 站点信息
    • 文章总数:163
    • 页面总数:0
    • 分类总数:6
    • 标签总数:20
    • 评论总数:0
    • 浏览总数:312004
    召唤伊斯特瓦尔