Home  >  Article  >  Backend Development  >  PHP method to remove null characters in strings

PHP method to remove null characters in strings

墨辰丷
墨辰丷Original
2018-06-12 14:20:543044browse

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

The examples in this article summarize the common methods of removing hollow characters in strings in PHP. The specific analysis is as follows:

php contains four functions that can remove spaces from strings:

trim() – removes the null characters at both ends of the string
ltrim() – removes the string Null characters at the front end
rtrim() – Remove the null characters at the end of the string
chop() – Same as rtrim().

The code is as follows:

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

Output result:

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

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

php operation text file to delete duplicate lines

Brief description of the method of intercepting Chinese characters in php to prevent garbled characters

php records user name and password based on cookies

The above is the detailed content of PHP method to remove null characters in strings. For more information, please follow other related articles on the PHP Chinese website!

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