php functions to delete blank spaces are: 1. Use the "str_replace()" function to delete; 2. Use the "strtr()" function to delete; 3. Use the encapsulated function "trimall" to delete.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
php What are the functions for deleting blank spaces? 3 ways to delete spaces in the middle of strings in php
The first one: use str_replace() function
The code is as follows:
<?php echo str_replace(' ', '', 'ab ab'); //输出 "abab' ?>
The second one: use strtr() The code of function
is as follows:
<?php echo strtr('ab ab', array(' '=>'')); // 输出 "abab" ?>
strtr() function is a bit special to use. In essence:
The code is as follows:
<?php strtr('ewb', 'web', '123') == strtr('ewb', array('e '=> '2', 'w' => '1', 'b' => '3')) == str_replace(array('e', 'w', 'b'), array('2', '1', '3'), 'ewb'); ?>
Third method: use The code of the encapsulated function
is as follows:
function trimall($str)//删除空格 { $qian=array(" "," ","\t","\n","\r"); $hou=array("","","","",""); return str_replace($qian,$hou,$str); }
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What are the functions to delete blank spaces in php?. For more information, please follow other related articles on the PHP Chinese website!