时间:2021-07-01 10:21:17 帮助过:6人阅读
php中包含四个可以去除字符串空格的函数:
trim() – 去除字符串两端的空字符
ltrim() – 去除字符串前端的空字符
rtrim() – 去除字符串末尾的空字符
chop() –同rtrim().
代码如下:
<?php $text = "\t \t jb51.net!\t \t "; $leftTrimmed = ltrim($text); $rightTrimmed = rtrim($text); $bothTrimmed = trim($text); print("leftTrimmed = ($leftTrimmed)\n"); print("rightTrimmed = ($rightTrimmed)\n"); print("bothTrimmed = ($bothTrimmed)\n"); ?>
输出结果:
leftTrimmed = (jb51.net! ) rightTrimmed = ( jb51.net!) bothTrimmed = (jb51.net!)
希望本文所述对大家的php程序设计有所帮助。