Home > Backend Development > PHP Problem > How to replace spaces in php

How to replace spaces in php

王林
Release: 2023-03-07 06:06:01
Original
4325 people have browsed it

How to replace spaces in php: You can use the preg_replace() function combined with the regular expression [/\s /] to replace spaces, such as [preg_replace('/\s /',' ',$contents) 】.

How to replace spaces in php

Function introduction:

preg_replace function performs a regular expression search and replacement.

(Recommended tutorial: php video tutorial)

Example:

Replace all spaces with empty spaces

$contents="    abc           ";
$contents=preg_replace('/\s+/','',$contents);
//结果$contents="abc";
Copy after login

Related Recommended: php training

The above is the detailed content of How to replace spaces in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template