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

PHP中文网
Release: 2023-03-16 21:20:02
Original
2283 people have browsed it

定义和用法

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

语法

chop(string,charlist)
Copy after login

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;            //输出结果
Copy after login

参数 描述

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

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

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

技术细节 返回值:

返回已修改的字符串。

实例 1

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

<?php
$str = "Hello World!\n\n";
echo $str;
echo chop($str);
?>
Copy after login

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

<!DOCTYPE html>
<html>
<body>
Hello World!
Hello World!
</body>
</html>
Copy after login

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

Hello World! Hello World!
Copy after login


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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template