字符串里貌似空格,如何删除?

WBOY
Libérer: 2016-07-06 13:54:00
original
1165 Les gens l'ont consulté

<code>$str ='                            Controllable Eu valence for photoluminescence tuning in apatite-typed';

在编码为GBK的情况下是'聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽Controllable Eu valence for photoluminescence tuning in apatite-typed';

在utf-8下是'                            Controllable Eu valence for photoluminescence tuning in apatite-typed';

</code>
Copier après la connexion
Copier après la connexion
<code>如何去除空格?</code>
Copier après la connexion
Copier après la connexion

回复内容:

<code>$str ='                            Controllable Eu valence for photoluminescence tuning in apatite-typed';

在编码为GBK的情况下是'聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽Controllable Eu valence for photoluminescence tuning in apatite-typed';

在utf-8下是'                            Controllable Eu valence for photoluminescence tuning in apatite-typed';

</code>
Copier après la connexion
Copier après la connexion
<code>如何去除空格?</code>
Copier après la connexion
Copier après la connexion

$str = preg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u','',$str);

http://php.net/manual/zh/regexp.reference.unicode.php

在选用 UTF-8模式时用于匹配通用字符类型

pC:所有的unicode“other”
pZ:所有的unicode“separator” ,所有空格和不可见字符

PHP合并多个连续的空格:
$output = preg_replace('/\s+/', ' ', $input);
\s 匹配任何空白字符,包括空格、制表符、换页符等等,等价于[ \f\n\r\t\v]
http://php.net/manual/zh/reference.pcre.pattern.syntax.php

$str = $str.replace(/s/g,'');

urlencode一下看看是什么字符,(是空格还是其他的)

Étiquettes associées:
php
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!