PHP chop() 函数
chop() 函数用于删除字符串右侧的空格或其他预定义字符。
语法
chop(string,charlist);
注意:chop()函数与Perl中的chop()函数不同,Perl中的chop()函数用于删除字符串中的最后一个字符。
参数 | 描述 | 必选/可选 |
---|---|---|
字符串 | 需要检查的字符串 | 必选 |
字符列表 | 字符列表参数为空 | 可选 |
示例1
<?php
str = "Hello World!";
echo "Your string is :".str."<br>";
echo "By using 'chop()' Functions is your string is: ".chop($str,"World!");
?>
输出:
Your string is :Hello World!
By using 'chop()' Functions is your string is: Hello
示例2
<?php
str = "Hello World!";
echo "Your string is :".str."<br>";
echo "By using 'chop()' Functions is your string is: ".chop($str);
?>
输出:
Your string is :Hello World!
By using 'chop()' Functions is your string is: Hello World!
示例3
<?php
str = "Hello World!\n\n";
echo "Your string is :".str."<br>";
echo "By using 'chop()' Functions is your string is: ".chop($str,"World!");
?>
输出:
Your string is :Hello World!
By using 'chop()' Functions is your string is: Hello World!