有人可以告诉我如何从php下面的数组中删除特殊字符
Array
(
[users] => Array
(
[name] => ASSOCIATION OF�CHIEFS OF USERS
)
)
预期产出:用户组合协会
由于
答案 0 :(得分:1)
使用as suggested in this SO answer函数的解决方案:
$arr = ['users' => ['name' => 'ASSOCIATION OF�CHIEFS OF USERS']];
$arr['users']['name'] = preg_replace("/[^\w [:punct:]]+/i", " ", $arr['users']['name']);
print_r($arr);
输出:
Array
(
[users] => Array
(
[name] => ASSOCIATION OF CHIEFS OF USERS
)
)
答案 1 :(得分:0)
只需使用str_replace()
echo str_replace ("�", " ", "ASSOCIATION OF�CHIEFS OF USERS");
答案 2 :(得分:0)
试试这个,
$str = "ASSOCIATION OF�CHIEFS OF USERS"; // your $arr['users']['name'];
echo preg_replace("/[^a-zA-Z0-9\s]/", "", $str);
OR
$arr['users']['name'] = preg_replace("/[^a-zA-Z0-9\s]/", "", $arr['users']['name']);
它会删除所有字符,但字母,数字和空格。
尝试一下,它会起作用。