Summary of common methods for removing null characters in strings in PHP_PHP Tutorial

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

Summary of common methods for removing hollow characters in strings in PHP

This article mainly introduces the common methods of removing hollow characters in strings in PHP, and analyzes trim() in PHP with examples. The usage skills of functions such as , ltrim(), rtrim() and chop() are of great practical value. Friends in need can refer to it

The example in this article summarizes the common methods of removing null 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:

?

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

4

5

6

1

2

3

leftTrimmed = (jb51.net! )

rightTrimmed = ( jb51.net!)

bothTrimmed = (jb51.net!)

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

?>
Output result: ?
1 2 3 leftTrimmed = (jb51.net! ) rightTrimmed = ( jb51.net!) bothTrimmed = (jb51.net!)
I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/969355.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/969355.htmlTechArticleSummary of the common methods of removing hollow characters in strings in PHP This article mainly introduces the common methods of removing hollow characters in strings in PHP Methods and examples analyze trim(), ltrim(), rtrim() and ch in php...
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