* 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 = 'm.sbmmt.com'; echo $str,'
'; echo strlen($str),'
'; echo '
';
//1.ltrim($str,$mask): Remove spaces from the left or specify the character
echo ltrim($str),'
'; echo strlen(ltrim($str)),'
'; echo $str1,'
'; echo strlen($str1),'
'; echo ltrim($str1, 'www.'),'
'; echo strlen(ltrim($str1, 'www.')),'
';
//2.rtrim($str,$mask): Delete spaces or specified characters from the right side
$str = ' php中文网 '; echo rtrim($str),'
'; echo strlen(rtrim($str)),'
';
//3.trim($str,$mask): Delete spaces or specified characters from the left and right sides
$str = ' php中文网 '; echo trim($str),'
'; echo strlen(trim($str)),'
'; echo '
';
//4.str_pad($str,$length,$mark,CONST): Use specific characters to pad the string to the specified length
$str1 = 'm.sbmmt.com'; echo strlen($str1),'
'; echo str_pad($str1, 20, '*', STR_PAD_RIGHT),'
'; //默认向右填充 echo str_pad($str1, 20, '*', STR_PAD_LEFT), '
'; //向左填充 echo str_pad($str1, 20, '*', STR_PAD_BOTH), '
'; //二边填充 echo '
';
//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, ','),'
'; echo chunk_split($str1, 7, '
');