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

How to remove whitespace characters in php

藏色散人
藏色散人Original
2020-07-30 10:19:433446browse

php method to remove whitespace characters: first create a PHP sample file; then delete all whitespace characters in the string through the "preg_replace("/\s /", "", $var);" method Can.

How to remove whitespace characters in php

Recommendation: "PHP Video Tutorial"

PHP Remove Whitespace Characters

Example 1:

<?php
    $var = "        This           is   a      beautiful        day!";
    // 删除字符串中的所有空白字符(不包括全角空格)
    $var1 = preg_replace("/\s+/", "", $var);
    echo $var1.&#39;<br>&#39;;
?>

Example 2:

<?php
    // 删除字符串中所有的字符(包括全角空格)
    $var = "         This           is   a      beautiful        day!";
    $var1 =preg_replace("/\s| /", "", $var);  // 已经包含了全角空格
    echo $var1.&#39;<br>&#39;;
?>

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