search
HomeBackend DevelopmentPHP ProblemHow to remove all spaces in php

How to remove all spaces in php

Jul 06, 2021 pm 02:56 PM
phpspace

php去掉所有的空格的方法是,使用正则表达式来实现,例如【preg_replace('# #','',$goodid)】。preg_replace函数会执行一个正则表达式的搜索和替换。

How to remove all spaces in php

本文操作环境:windows10系统、php 7.3、thinkpad t480电脑。

在php中如果我们要去掉字符串中所有的空格,最快捷有效的方式就是使用正则表达式。下面我们就来一起看下。

preg_replace 函数执行一个正则表达式的搜索和替换。

举个小例子:

<?php
$string = &#39;google 123, 456&#39;;
$pattern = &#39;/(\w+) (\d+), (\d+)/i&#39;;
$replacement = &#39;phpphp ${2},$3&#39;;
echo preg_replace($pattern, $replacement, $string);
?>

运行结果:

phpphp 123,456

下面我们使用正则匹配去除所有的空格

preg_replace(&#39;# #&#39;,&#39;&#39;,$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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

DVWA

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

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

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

Zend Studio 13.0.1

Powerful PHP integrated development environment