Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the methods of clearing spaces in a string by php

Shulou Source: shulou.com Published: 2022-06-03 10:38:19 10月04日 Update

This article shows you what php can do to remove spaces in a string. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Php clears spaces in strings by regular expressions, str_replace () functions, and strtr () functions, such as [preg_replace ('# #','','ab ab');].

This article operating environment: windows10 system, php 7, thinkpad T480 computer.

There are many ways to clear spaces in PHP, such as regular expressions, str_replace () function, strtr () function, and so on. When we use these methods, we will find that it is very easy to clear the spaces in the string.

Let's take a look at how these methods remove spaces in a string.

The first is regularization:

The second uses the str_replace () function:

The third uses the strtr () function:

The use of the strtr () function is a little special, in essence:

What are the above methods for php to remove spaces in strings? have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Functions methods characters strings spaces regularities content skills knowledge expressions concise concise things essence that is articles times more environment computer Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MySQL Shulou Information Redmi NVidia