Home  >  Article  >  Backend Development  >  Summary of common methods for removing hollow characters in strings in PHP, summary of hollow characters in PHP strings_PHP tutorial

Summary of common methods for removing hollow characters in strings in PHP, summary of hollow characters in PHP strings_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:02:44848browse

A summary of common methods for removing hollow characters in strings in PHP, a summary of hollow characters in PHP strings

The examples in this article summarize the common methods of removing hollow characters in strings in PHP. Share it with everyone for your reference. The specific analysis is as follows:

php contains four functions that can remove spaces from strings:

trim() – removes null characters from both ends of a string
ltrim() – removes null characters at the front of a string
rtrim() – removes null characters at the end of a string
chop() – same as rtrim().

The code is as follows:

<&#63;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");
&#63;>

Output result:

leftTrimmed = (jb51.net! )
rightTrimmed = ( jb51.net!)
bothTrimmed = (jb51.net!)

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/969499.htmlTechArticleSummary of common methods for removing hollow characters in strings in PHP, summary of hollow characters in PHP strings This article summarizes the removal of strings in PHP with examples Common method for hollow characters. Share it with everyone for your reference. Tool...
Statement:
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