* 1.ltrim($str,$mask): Delete spaces or specified characters from the left
* 2.rtrim($str,$mask): Delete spaces or specified characters from the right
* 3.trim($str,$mask): Remove spaces or specified characters from the left and right edges
* 4.str_pad($str,$length,$mark,CONST): Use specific characters to Fill the string to the specified length
* You can use three constants to specify the direction: STR_PAD_LEFT/STR_PAD_RIGHT/STR_PAD_BOTH, and use spaces by default
* 5.chunk_split($str, $length,[$end ]): Cut the string into small pieces according to size, you can specify the delimiter
$str = ' php中文网 '; //左边二个空格,右边三个空格 $str1 = 'www.php.cn'; echo $str,'<br>'; echo strlen($str),'<br>'; echo '<hr color="red">';
//1.ltrim($str,$mask): Remove spaces from the left or specify the character
echo ltrim($str),'<br>'; echo strlen(ltrim($str)),'<br>'; echo $str1,'<br>'; echo strlen($str1),'<br>'; echo ltrim($str1, 'www.'),'<br>'; echo strlen(ltrim($str1, 'www.')),'<br>';
//2.rtrim($str,$mask): Delete spaces or specified characters from the right side
$str = ' php中文网 '; echo rtrim($str),'<br>'; echo strlen(rtrim($str)),'<br>';
//3.trim($str,$mask): Delete spaces or specified characters from the left and right sides
$str = ' php中文网 '; echo trim($str),'<br>'; echo strlen(trim($str)),'<br>'; echo '<hr>';
//4.str_pad($str,$length,$mark,CONST): Use specific characters to pad the string to the specified length
$str1 = 'www.php.cn'; echo strlen($str1),'<br>'; echo str_pad($str1, 20, '*', STR_PAD_RIGHT),'<br>'; //默认向右填充 echo str_pad($str1, 20, '*', STR_PAD_LEFT), '<br>'; //向左填充 echo str_pad($str1, 20, '*', STR_PAD_BOTH), '<br>'; //二边填充 echo '<hr>';
//5.chunk_split($str, $length,[$end]): Cut the string into small pieces according to size, you can specify the separator
$str1 = '12345678901234567890'; echo chunk_split($str1, 7, ','),'<br>'; echo chunk_split($str1, 7, '<br>');