Home > Backend Development > PHP Problem > How to remove whitespace characters in php

How to remove whitespace characters in php

Guanhui
Release: 2023-03-01 06:16:01
Original
3792 people have browsed it

How to remove whitespace characters in php

How to remove white characters in php

In php, you can use the function "preg_replace" to remove white characters. The function of this function executes a regular When using expression search and replacement, you need to pass in 3 parameters. The first parameter is the regular expression "/\s /", the second parameter is empty, and the third parameter is the string from which whitespace characters are to be removed. , and finally receive the return value.

Usage example:

<?php
    $var = "        This           is   a      beautiful        day!";

    // 删除字符串中的所有空白字符(不包括全角空格)
    $var = preg_replace("/\s+/", "", $var);
    echo $var;
?>
Copy after login

Recommended tutorial: "PHP Tutorial"

The above is the detailed content of How to remove whitespace characters 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