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
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:
<?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!)
I hope this article will be helpful to everyone’s PHP programming design.