Home  >  Article  >  Backend Development  >  How to remove spaces from string in php

How to remove spaces from string in php

藏色散人
藏色散人Original
2020-12-02 09:34:232396browse

php method to remove string spaces: first create a PHP sample file; then define a trimall method; finally use "str_replace($qian,$hou,$str);" to implement the function of removing string spaces. Can.

How to remove spaces from string in php

The operating environment of this tutorial: Windows 7 system, PHP version 7.1. This method is suitable for all brands of computers.

Recommendation: "PHP Video Tutorial"

php removes all spaces in the string

In fact, it is the trim function The extension

trim can only remove spaces on both sides of the string

php code

function trimall($str)//删除空格
{
    $qian=array(" "," ","\t","\n","\r");
         $hou=array("","","","","");
    return str_replace($qian,$hou,$str);    
}

The above is the detailed content of How to remove spaces from string 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