php如何去除字符串首尾两端空格?
可以使用trim()函数
定义和用法:
trim()函数可移除字符串两端的空白字符或其他预定义字符。
语法:
trim(string,charlist)
string:必需。规定要检查的字符串。charlist:可选。规定从字符串中删除哪些字符。
<?php$str = " hello world! ";echo "without trim: " . $str;echo "<br>";echo "with trim: " . trim($str);?>
上述代码输出:
without trim: hello world!
with trim: hello world!
相关参考:
以上就是php如何去除字符串首尾两端空格的详细内容。