在PHP 5.2中修剪Unicode空白 [英] Trim unicode whitespace in PHP 5.2

查看:89
本文介绍了在PHP 5.2中修剪Unicode空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何修剪string(6) " page",其中第一个空格是0xc2a0不间断空格?

How can I trim a string(6) " page", where the first whitespace is a 0xc2a0 non-breaking space?

我尝试了trim()preg_match('/^\s*(.*)\s*$/u', $key, $m);.

另一个问题:如何可靠地复制这些字符?它们似乎被转换为常规"空间,因此很难调试.

Another question: How can I reliably copy these characters? They seem to be converted to "normal" spaces, which makes it hard to debug.

推荐答案

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

这篇关于在PHP 5.2中修剪Unicode空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆