Home > Article > Backend Development > php ltrim() rtrim() trim() removes character spaces_PHP tutorial
The trim function in php cannot automatically delete all spaces like the one in asp. It professionally provides the rtrim() trim() function. You can refer to it if you need it.
<?php $str=" 去除前后空格 "; echo "方括号中为原始字符串:[".$str."] "; echo "原始字符串长度:".strlen($str)." "; $str1=ltrim($str); echo "执行ltrim()之后的长度:".strlen($str1)." "; $str2=rtrim($str); echo "执行rtrim()之后的长度:".strlen($str2)." "; $str3=trim($str); echo "执行trim()之后的长度:".strlen($str3)." "; echo "去掉首尾空格之后的字符串:[".$str3."]"; ?>