Get the App
SLTechnology News&Howtos  ›  Development  › 

How php removes variable spaces

Shulou Source: shulou.com Published: 2022-06-03 14:03:07 11月13日 Update

This article mainly introduces php how to remove variable spaces, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

Php removes variable spaces: 1, delete string spaces by trim method; 2, replace spaces with preg_replace method; 3, replace spaces with str_replace function.

This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer

How does php remove variable spaces?

Php removes whitespace from a string

1. Common methods trim

Examples:

$test = "abc"; / / method 1: the function converts HTML entities to characters. $converted = html_entity_decode ($test), chr (0xc2) .chr (0xa0); / / method 2: $converted = strtr ($myHTML, array_flip (get_html_translation_table (HTML_ENTITIES, ENT_QUOTES)); / / php:45:string 'abc' (length=5) $converted = trim ($converted,chr (0xC2) .chr (0xA0)); / / should workvar_dump ($converted)

Hexadecimal conversion: 0xC2 to 0xA0 to space

2, replace with preg_replace

Examples:

$str = 'test'; $str = preg_replace (' /', $str); / / will be changed to 'test'3, replace with str_replace

Case study

$str= "t e st"; $str=str_replace ("",'', $str); echo $str thank you for reading this article carefully. I hope the article "how to remove variable spaces in php" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Spaces methods variables articles examples characters functions strings values interests hexadecimal at the same time entities commonly used more friends environment computers knowledge systems Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Docker MySQL macOS Redmi