我有以下数组:
[0] => Array
(
[0] => 3,38 m
[1] => 13,30 s
[2] => 5,41 m
[3] => ESE
[4] => 294º
[5] => 32,76 km/h
[6] => W
[7] => 266º
[8] => 16,27 ºC
[9] => 12,80 ºC
[10] => 0
)
我想在将数据添加到数据库之前对其进行清理。
此功能几乎存在,但不会删除特殊字符:
function cleanUp(&$value,$key)
{
$cleaner2 = array("km/h"," ","m","s","º","ºC");
$value = str_replace($cleaner2, "", $value);
}
array_walk($newArray[0],"cleanUp");
我已经研究过对数组进行编码,但我不确定它现在有什么编码?我可以修剪数组值,但觉得这很不雅。
有任何想法吗?
解决方案: 我从标题中省略了字符集!
header('Content-type: application/json; charset=UTF-8');
这使我的简单 cleanUp 函数可以工作,因为它删除了 Â,然后匹配以下 cleanUp 数组值:
$cleaner2 = array("km/h"," ","m","s","º","ºC","C");