<?php$text = "\t\tThese are a few words :) ... "; $binary = "\x09Example string\x0A"; $hello = "Hello World"; var_dump($text, $binary, $hello);print "\n";$trimmed = trim($text); var_dump($trimmed);$trimmed = trim($text, " \t."); var_dump($trimmed);$trimmed = trim($hello, "Hdle"); var_dump($trimmed);// trim the ASCII control characters at the beginning and end of $binary // (from 0 to 31 inclusive) $clean = trim($binary, "\x00..\x1F"); var_dump($clean);?> ltrim是将左边符合要求的去掉。你的字符串左边第一个是空格,所以不符合要求,就没变化了。
Strip whitespace (or other characters) from the beginning of a string.
$str=" @Hello@@ k";
$trimed = ltrim($str,"@");
var_dump($trimed);
?>
$binary = "\x09Example string\x0A";
$hello = "Hello World";
var_dump($text, $binary, $hello);print "\n";$trimmed = trim($text);
var_dump($trimmed);$trimmed = trim($text, " \t.");
var_dump($trimmed);$trimmed = trim($hello, "Hdle");
var_dump($trimmed);// trim the ASCII control characters at the beginning and end of $binary
// (from 0 to 31 inclusive)
$clean = trim($binary, "\x00..\x1F");
var_dump($clean);?> ltrim是将左边符合要求的去掉。你的字符串左边第一个是空格,所以不符合要求,就没变化了。
echo ltrim($str,"@ ");
trim,ltrim,rtrim的第二个参数是一个chars list,只要开头或者结尾的字符match到(不论顺序),都会被删除,这点很方便,也有时候容易会让人犯错,比如
$str = "hello";
echo trim($str,"hol");//结果是只剩下一个'e'
$str=" @Hello@@ k";
$trimed= ltrim(ltrim($str),"@");echo $trimed;