trim

来自AI助手的总结
PHP的trim()函数用于删除字符串两端的空白字符和其他预定义字符。


PHP trim() 函数

定义和用法

trim() 函数从字符串的两端删除空白字符和其他预定义字符。

语法

trim(string,charlist)

参数 描述
string 必需。规定要检查的字符串。
charlist 可选。规定要转换的字符串。如果省略该参数,则删除以下所有字符:

  • “” – NULL

  • “t” – tab

  • “n” – new line

  • “x0B” – 纵向列表符

  • “r” – 回车

  • ” ” – 普通空白字符

例子

例子 1


";
echo "With trim: " . trim($str);
?>

输出:

Without trim: Hello World!
With trim: Hello World!

HTML 源码:


Without trim:     Hello World!    
With trim: Hello World!

例子 2

";
echo "With trim: " . trim($str);
?>

输出:

Without trim: Hello World!
With trim: Hello World!

HTML 源码:


Without trim: 
Hello World!

With trim: Hello World!

温馨提示: 本文最后更新于2025-03-02 00:11:12,某些文章具有时效性,若有错误或已失效,请在下方 留言或联系 蚂蚁官方
© 版权声明
THE END
喜欢就支持一下吧
点赞10赞赏 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容