Home > Article > Backend Development > How to remove spaces from string in php
php method to remove string spaces: first create a PHP sample file; then define a trimall method; finally use "str_replace($qian,$hou,$str);" to implement the function of removing string spaces. Can.
The operating environment of this tutorial: Windows 7 system, PHP version 7.1. This method is suitable for all brands of computers.
Recommendation: "PHP Video Tutorial"
php removes all spaces in the string
In fact, it is the trim function The extension
trim can only remove spaces on both sides of the string
php code
function trimall($str)//删除空格 { $qian=array(" "," ","\t","\n","\r"); $hou=array("","","","",""); return str_replace($qian,$hou,$str); }
The above is the detailed content of How to remove spaces from string in php. For more information, please follow other related articles on the PHP Chinese website!