php去除字符串中空字符的方法有哪些

PHPz
Release: 2020-06-24 14:20:54
Original
1315 people have browsed it

php去除字符串中空字符的方法有哪些

php去除字符串中空字符的方法有哪些?

本文实例总结了php去除字符串中空字符的常用方法。分享给大家供大家参考。具体分析如下:

php中包含四个可以去除字符串空格的函数:

trim() – 去除字符串两端的空字符
ltrim() – 去除字符串前端的空字符
rtrim() – 去除字符串末尾的空字符
chop() –同rtrim().
Copy after login

代码如下:

<?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");
?>
Copy after login

输出结果:

leftTrimmed = (bitsCN.com! )
rightTrimmed = ( bitsCN.com!)
bothTrimmed = (bitsCN.com!)
Copy after login

更多相关技术知识,请访问PHP中文网

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template