我想在用选项卡爆炸之前将标签从 array_values() 内的值中剥离出来。
我尝试使用下面的这一行,但出现错误,
$output = implode("\t",strip_tags(array_keys($item)));
理想情况下,我想从值中去掉换行符、双空格、制表符,
$output = implode("\t",preg_replace(array("/\t/", "/\s{2,}/", "/\n/"), array("", " ", " "), strip_tags(array_keys($item))));
但我觉得我的方法不正确!
这是整个函数,
function process_data($items){
# set the variable
$output = null;
# check if the data is an items and is not empty
if (is_array($items) && !empty($items))
{
# start the row at 0
$row = 0;
# loop the items
foreach($items as $item)
{
if (is_array($item) && !empty($item))
{
if ($row == 0)
{
# write the column headers
$output = implode("\t",array_keys($item));
$output .= "\n";
}
# create a line of values for this row...
$output .= implode("\t",array_values($item));
$output .= "\n";
# increment the row so we don't create headers all over again
$row++;
}
}
}
# return the result
return $output;
}
如果您有任何解决此问题的想法,请告诉我。谢谢!
strip_tags
仅适用于字符串,不适用于数组输入。因此你必须在之后应用它implode
制作了输入的字符串。
$output = strip_tags(
implode("\t",
preg_replace(
array("/\t/", "/\s{2,}/", "/\n/"),
array("", " ", " "),
array_keys($item)
)
)
);
您必须测试它是否能给您带来所需的结果。我不知道 preg_replace 的作用是什么。
否则你可以使用array_map("strip_tags", array_keys($item))
首先删除标签(如果确实有任何重要的\t
在字符串的标签内。)
(不知道你的大功能是什么。)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)