当前位置: 首页> 函数类别大全> str_ends_with

str_ends_with

检查字符串是否以给定的子字符串结尾
名称:str_ends_with
分类:字符串
所属语言:php
一句话介绍:检查字符串是否以给定的子字符串结尾

str_ends_with 函数

适用 PHP 版本

PHP 8.0.0 及以上版本

函数说明

str_ends_with 函数用于检查一个字符串是否以指定的子字符串结尾。

函数语法

str_ends_with(string $haystack, string $needle): bool

参数

$haystack (string): 需要检查的字符串。

$needle (string): 要检查的子字符串。

返回值

返回布尔值 true 如果字符串 $haystack 以子字符串 $needle 结尾,否则返回 false

示例

以下是使用 str_ends_with 函数的示例:

  $string1 = "Hello, World!";
  $string2 = "World";

  if (str_ends_with($string1, $string2)) {
      echo "字符串 '$string1' 以 '$string2' 结尾。";
  } else {
      echo "字符串 '$string1' 不以 '$string2' 结尾。";
  }
  

示例代码的说明

在此示例中,我们定义了两个字符串变量 $string1$string2。我们使用 str_ends_with 来检查 $string1 是否以 $string2 结尾。如果是,输出提示字符串以该子字符串结尾;否则输出字符串不以该子字符串结尾。

同类函数
  • 将字符由一种 Cyrillic 字符转换成另一种 convert_cyr_string

    convert_cyr_string

    将字符由一种Cyrillic字符转换成另
  • 计算字符串的sha1哈希值 sha1

    sha1

    计算字符串的sha1哈希值
  • 将一个一维数组的值转化为字符串 implode

    implode

    将一个一维数组的值转化为字符串
  • 将字符串转换为数组 str_split

    str_split

    将字符串转换为数组
  • 不区分大小写的strstr stristr

    stristr

    不区分大小写的strstr
  • 删除字符串末端的空白字符(或者其他字符) rtrim

    rtrim

    删除字符串末端的空白字符(或者其他字符)
  • 将数字格式化成货币字符串 money_format

    money_format

    将数字格式化成货币字符串
  • 查找字符串首次出现的位置(不区分大小写) stripos

    stripos

    查找字符串首次出现的位置(不区分大小写)