PHP convert unicode spaces to ascii spaces
So I'm having a problem where I believe what's happening is I'm receiving data that uses some unicode spaces and some ascii spaces, such that certain strings that appear the same are not equivalent, for example, "water resistant" != "water resistant". These strings appear differently in my database, however, with the weird characters you normally see when there's a multibyte character: "water resistantÂ" and " water resistant".
I would like a way to make all spaces be ascii spaces, or if easier, all spaces be multibyte spaces.
I've tried using preg_replace, but then the strings no longer read like valid multibyte strings anymore. (Multibyte characters in the strings will appear as garbage).
preg_replace('/[pZpC]/',' ',$field);
I've also tried using mb_ereg_replace, but it had no effect.
mb_ereg_replace('/[pZpC]/',' ',$field)
你可以找到并用标准的ASCII空格替换它们,如果你想通过:
$string = str_replace("xc2xa0", "x20", $string);
It looks like preg_replace('/[pZpC]/u',' ',$field);
works (forgot the u at the end of the regex)
我认为你正在寻找utf8_decode($field)
。
上一篇: 安全地连接多字节字符串