php去除字符串中空字符的方法有哪些?
本文实例总结了php去除字符串中空字符的常用方法。分享给大家供大家参考。具体分析如下:
php中包含四个可以去除字符串空格的函数:
trim() – 去除字符串两端的空字符 ltrim() – 去除字符串前端的空字符 rtrim() – 去除字符串末尾的空字符 chop() –同rtrim().
代码如下:
<?php $text = "\t \t bitsCN.com!\t \t "; $leftTrimmed = ltrim($text); $rightTrimmed = rtrim($text); $bothTrimmed = trim($text); print("leftTrimmed = ($leftTrimmed)\n"); print("rightTrimmed = ($rightTrimmed)\n"); print("bothTrimmed = ($bothTrimmed)\n"); ?>
输出结果:
立即学习“PHP免费学习笔记(深入)”;
leftTrimmed = (bitsCN.com! ) rightTrimmed = ( bitsCN.com!) bothTrimmed = (bitsCN.com!)
更多相关技术知识,请访问PHP中文网!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号