php去除字符串中空字符的常用方法小结_PHP教程

WBOY
Release: 2016-07-13 10:02:55
Original
910 people have browsed it

php去除字符串中空字符的常用方法小结

 这篇文章主要介绍了php去除字符串中空字符的常用方法,实例分析了php中的trim()、ltrim()、rtrim()及chop()等函数的使用技巧,非常具有实用价值,需要的朋友可以参考下

 

 

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

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

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

代码如下:

?

1

2

3

4

5

6

7

8

9

$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");

?>

输出结果:

?

1

2

3

leftTrimmed = (jb51.net! )

rightTrimmed = ( jb51.net!)

bothTrimmed = (jb51.net!)

希望本文所述对大家的php程序设计有所帮助。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/969355.htmlTechArticlephp去除字符串中空字符的常用方法小结 这篇文章主要介绍了php去除字符串中空字符的常用方法,实例分析了php中的trim()、ltrim()、rtrim()及ch...
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!