How to remove full-width spaces in php

藏色散人
Release: 2023-03-10 18:56:01
Original
2469 people have browsed it

How to remove full-width spaces in php: First create a PHP sample file; then use the "function myTrim($str){...}" method to remove full-width spaces.

How to remove full-width spaces in php

## The operating environment of this article: Windows 7 system, PHP version 7.1 , Dell G3 computer.

How to remove full-width spaces in php?

php common methods for removing empty characters and spaces, full-width spaces, line breaks, etc. in strings

    • Function to remove spaces from strings
    • Filter spaces, full-width spaces, line breaks
    • Use regular preg_replace function

Function to remove string spaces

trim() – Removes null characters from both ends of the string

ltrim() – Removes null characters from the front of the string
rtrim() – Removes null characters from the end of the string
chop() – Same as rtrim( ).

"; print("rightTrimmed = ($rightTrimmed)"); echo "
"; print("bothTrimmed = ($bothTrimmed)"); echo "
"; ?>
Copy after login

Output results


How to remove full-width spaces in php

Filter spaces, full-width spaces, line breaks

function myTrim($str) { $search = array(" "," ","\n","\r","\t"); $replace = array("","","","",""); return str_replace($search, $replace, $str); } echo '当前字符串内容:'.$str = 'www.qipa250.com QIPA250 奇葩天地网 qipa250.com'; echo "
"; echo '过滤后的字符串内容:'.myTrim($str); echo "
";
Copy after login

The results are as follows:


How to remove full-width spaces in php

Use the regular preg_replace function

echo preg_replace('# #', '', 'ab ab'); //输出 "abab"
Copy after login
Recommended study: "

PHP Video Tutorial"

The above is the detailed content of How to remove full-width spaces in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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!