Home >Backend Development >PHP Tutorial >How to delete left and right spaces in php, delete left spaces in php_PHP tutorial
The example in this article describes how to delete left and right spaces in PHP. Share it with everyone for your reference. The specific method is as follows:
Deleting functions in PHP is much more specific than in JS. In addition to the trim() function, there are also ltrim() and rtrim() functions. They need to delete the spaces around and around them respectively. In addition to these three functions, you can also use regular expressions. Delete.
ltrim() function: ltrim($str, $charlist)
$str represents the string being processed, $charlist is the special character to be deleted, if it is empty, the space at the left end will be removed, the code is as follows:
rtrim() function: rtrim($str, $charlist)
$str represents the string being processed, $charlist is the special character to be deleted, if it is empty, the space at the right end will be removed, the code is as follows:
trim() function, first remove the leading and trailing spaces, the code is as follows:
replaces with a regular expression, which is more powerful. PHP removes spaces at the beginning and end of the string (including full-width). The code is as follows:
I hope this article will be helpful to everyone’s PHP programming design.