How to convert spaces into nbsp characters in php

青灯夜游
Release: 2023-03-15 20:06:01
Original
2852 people have browsed it

Method: 1. Use str_replace(), the syntax "str_replace(" "," ",$str)"; 2. Use preg_replace() with regular expressions, the syntax "preg_replace('/\s / '," ",$str)".

How to convert spaces into nbsp characters in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

nbspSpace character

In HTML, is a space entity, also known as a non-breaking space. It is the most common space that we use the most. Most people may only be exposed to it. It is a space generated by pressing the space key. . In HTML, if you use the space bar to generate this space, the spaces will not accumulate (only count as 1). You need to use html entity representation to accumulate,

php method to convert spaces into nbsp characters

  • Use str_replace () Function

  • Use preg_replace() function

1. Use str_replace() function

"; $newStr = str_replace(" ", " ", $str); echo $newStr; ?>
Copy after login

How to convert spaces into nbsp characters in php

2. Use the preg_replace() function

Use the preg_replace() function with the regular expression "/\s /" to replace.

"; $newStr = preg_replace('/\s+/', " ", $str); echo $newStr; ?>
Copy after login

How to convert spaces into nbsp characters in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to convert spaces into nbsp characters in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!