正文  软件开发 > PHP编程技术 >

PHP字符串函数-trim()实例用法,字符串-trim

PHP字符串函数-trim()实例用法,字符串-trimstring trim ( string $str [, string $charlist = ” x0B” ] )此函数...

PHP字符串函数-trim()实例用法,字符串-trim

string trim ( string $str [, string $charlist = ” x0B” ] )
此函数返回字符串 str 去除首尾空白字符后的结果。如果不指定第二个参数, trim() 将去除这些字符:
1.” ” (ASCII 32 (0x20)),普通空格符。
2. “ ” (ASCII 9 (0x09)),制表符。
3. “ ” (ASCII 10 (0x0A)),换行符。
4. “ ” (ASCII 13 (0x0D)),回车符。
5. “” (ASCII 0 (0x00)),空字节符。
6. “x0B” (ASCII 11 (0x0B)),垂直制表符。

<?php
    $text = "		These are a few words :) ...  ";
    $binary = "x09Example stringx0A";
    $hello = "Hello World";
    $str = "##	使用函数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();删除字符串末端的空白字符(或者其他字符)

http://www.bkjia.com/PHPjc/1228526.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1228526.htmlTechArticlePHP字符串函数-trim()实例用法,字符串-trim string trim ( string $str [, string $charlist = ” x0B” ] ) 此函数返回字符串 str 去除首尾空白字符后...