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
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!