php去掉所有的空格的方法是,使用正则表达式来实现,例如【preg_replace('# #','',$goodid)】。preg_replace函数会执行一个正则表达式的搜索和替换。
本文操作环境:windows10系统、php 7.3、thinkpad t480电脑。
在php中如果我们要去掉字符串中所有的空格,最快捷有效的方式就是使用正则表达式。下面我们就来一起看下。
preg_replace 函数执行一个正则表达式的搜索和替换。
举个小例子:
<?php $string = 'google 123, 456'; $pattern = '/(\w+) (\d+), (\d+)/i'; $replacement = 'phpphp ${2},$3'; echo preg_replace($pattern, $replacement, $string); ?>
运行结果:
phpphp 123,456
下面我们使用正则匹配去除所有的空格
preg_replace('# #','',$goodid)
相关视频教程分享:php视频教程
The above is the detailed content of How to remove all spaces in php. For more information, please follow other related articles on the PHP Chinese website!

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

Atom editor mac version download
The most popular open source editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1
Powerful PHP integrated development environment
