string trim ( string $str [, string $charlist = ” \t\n\r\0\x0b” ] )
此函数返回字符串 str 去除首尾空白字符后的结果。如果不指定第二个参数, trim() 将去除这些字符:
1.” ” (ascii 32 (0x20)),普通空格符。
2. “\t” (ascii 9 (0x09)),制表符。
3. “\n” (ascii 10 (0x0a)),换行符。
4. “\r” (ascii 13 (0x0d)),回车符。
5. “\0” (ascii 0 (0x00)),空字节符。
6. “\x0b” (ascii 11 (0x0b)),垂直制表符。
<?php $text = "\t\tThese are a few words :) ... "; $binary = "\x09Example string\x0A"; $hello = "Hello World"; $str = "##\t使用函数trim去掉字符串两端特定字符####"; $new_text = trim($text); $new_binary = trim($binary); $new_hello = trim($hello); $new_str = trim($str,"#"); echo $new_text; //These are a few words :) ... echo $new_binary; //Example string echo $hello; //Hello World echo $new_str; //使用函数trim去掉字符串两端特定字符 ?>
以上函数功能,同时适用于ltrim()、rtrim(),这2个函数
1、ltrim();删除字符串开头的空白字符(或其他字符)
2、rtrim();删除字符串末端的空白字符(或者其他字符)
以上就是PHP函数trim()实例的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号