Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How php removes variable spaces

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report