我想使用以下函数清除数组中的空值:
function remove_empty_cells($data)
{
$findthis = array("/\r\n/u", "/\n/u", "/\r/u", "/\s+/u", "~\x{00a0}~");
for($i=0; $i<count($data); $i++)
{
$data[$i] = preg_replace($findthis, " ", $data[$i]);
$data[$i] = htmlspecialchars_decode(htmlspecialchars($data[$i], ENT_SUBSTITUTE, 'UTF-8'));
if (empty($data[$i]) ||
mb_strlen($data[$i]) < strlen($data[$i]) ||
is_null($data[$i]) ||
$data[$i] = " " ||
$data[$i] = "" ||
$data[$i] == "0")
{
array_splice($data, $i, 1);
};//end if
};//end for
return $data;
};//end func
空值并未消失,我无法识别它们...
数据如下:
array (
0 => '
',
1 => 'BEGIN:VCARD
',
2 => '
',
3 => '
',
4 => '
',
5 => '
',
6 => '
',
7 => 'VERSION:2.1
',
可能存在一些编码问题或其他问题...它看起来不像是多字节字符... 我得到的结果是:
array (
0 => 'BEGIN:VCARD
',
1 => '
',
2 => '
',
3 => 'VERSION:2.1
',
...
\x{00a0}
也不能获得Unicode标志呢? - mickmackusa