Home  >  Article  >  Backend Development  >  How to remove whitespace characters in php

How to remove whitespace characters in php

Guanhui
GuanhuiOriginal
2020-05-08 15:59:003733browse

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;
?>

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!

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