1、定义含空格的字符串。<?php $str=" hello matchall ";
2、使用trim函数:$str1=trim($str);
3、统计处理后字符串长度:echo "处理后有".strlen($str1)."个字符";
4、echo &孥恶膈茯quot;<br />";echo "处理前有".strlen($str)."个字符";
5、为了对比,加之前处理的长度。结果如图:
1、定义含空格的字符串。<?php $str=" hello matchall ";
2、使用trim函数:$str1=trim($str);
3、统计处理后字符串长度:echo "处理后有".strlen($str1)."个字符";
4、echo &孥恶膈茯quot;<br />";echo "处理前有".strlen($str)."个字符";
5、为了对比,加之前处理的长度。结果如图: