当前位置: 首页> 函数类别大全> 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 结尾。如果是,输出提示字符串以该子字符串结尾;否则输出字符串不以该子字符串结尾。

同类函数
  • 转换十六进制字符串为二进制字符串 hex2bin

    hex2bin

    转换十六进制字符串为二进制字符串
  • 返回字符串的一部分 substr

    substr

    返回字符串的一部分
  • 从字符串中删除 HTML和PHP标记 strip_tags

    strip_tags

    从字符串中删除HTML和PHP标记
  • 标记分割字符串 strtok

    strtok

    标记分割字符串
  • 对字符串执行rot13转换 str_rot13

    str_rot13

    对字符串执行rot13转换
  • 二进制安全比较字符串(从偏移位置比较指定长度) substr_compare

    substr_compare

    二进制安全比较字符串(从偏移位置比较指定
  • 删除字符串末端的空白字符(或者其他字符) rtrim

    rtrim

    删除字符串末端的空白字符(或者其他字符)
  • 返回格式化的字符串 sprintf

    sprintf

    返回格式化的字符串