Home  >  Article  >  Backend Development  >  PHP deletes whitespace characters at the end of the string function chop()

PHP deletes whitespace characters at the end of the string function chop()

PHP中文网
PHP中文网Original
2017-11-01 10:39:062141browse

定义和用法

chop() 函数移除字符串右侧的空白字符或其他预定义字符。

语法

chop(string,charlist)

chop执行去除空格处理,get_html_translation_table返回转化列表到变量,定义包括HTML编码的字符串htmlentities,htmlspecialchars_decode 定义包含HTML特殊字符的字符串,nl2br quotemeta rtrim等.

定义和用法:chop() 函数从字符串的末端开始删除空白字符或其他预定义字符,该函数的 rtrim() 函数的别名.

语法:chop(string,charlist),代码如下:

复制代码代码如下:

$str="i'm a   teacher  ";          //定义字符串 
$result=chop($str);           //执行去除空格处理 
echo $result;            //输出结果

参数          描述

string    必需。规定要检查的字符串。    

charlist    可选。规定从字符串中删除哪些字符。
如果 charlist 参数为空,则移除下列字符:

"\0" - NULL
"\t" - 制表符
"\n" - 换行
"\x0B" - 垂直制表符
"\r" - 回车
" " - 空格

技术细节   返回值:

返回已修改的字符串。    

实例 1

移除字符串右侧的换行符(\n):

上面代码的 HTML 输出如下(查看源代码):




Hello World!
Hello World!

上面代码的浏览器输出如下:

Hello World! Hello World!


The above is the detailed content of PHP deletes whitespace characters at the end of the string function chop(). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn