这篇文章主要介绍了php中3种方法删除字符串中间的空格,需要的朋友可以参考下
第一种:使用正则
echo preg_replace('# #', '', 'ab ab');
//输出 "abab"
?>
第二种:使用str_replace()函数
echo str_replace(' ', '', 'ab ab');
//输出 "abab'
?>
第三种:使用strtr()函数
echo strtr('ab ab', array(' '=>''));
// 输出 "abab"
?>
strtr()函数使用上有点特别,实质上:
strtr('ewb', 'web', '123') ==
strtr('ewb', array('e '=> '2', 'w' => '1', 'b' => '3')) ==
str_replace(array('e', 'w', 'b'), array('2', '1', '3'), 'ewb');
?>
第四种:使用封装函数
function trimall($str)//删除空格
{
$qian=array(" "," ","\t","\n","\r");
$hou=array("","","","","");
return str_replace($qian,$hou,$str);
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
