php中包含四个可以去除字符串空格的函数:
trim() – 去除字符串两端的空字符
ltrim() – 去除字符串前端的空字符
rtrim() – 去除字符串末尾的空字符
chop() –同rtrim().
<?php $text = "\t \t 75271.com!\t \t "; $leftTrimmed = ltrim($text); $rightTrimmed = rtrim($text); $bothTrimmed = trim($text); print("leftTrimmed = ($leftTrimmed)\n"); print("rightTrimmed = ($rightTrimmed)\n"); print("bothTrimmed = ($bothTrimmed)\n"); ?>
输出结果
leftTrimmed = (75271.com! ) rightTrimmed = ( 75271.com!) bothTrimmed = (75271.com!)