How to remove whitespace characters in php

藏色散人
Release: 2023-03-03 14:26:02
Original
3476 people have browsed it

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;;
?>
Copy after login

Example 2:

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

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:
php
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