我希望能够在使用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;
}
请告诉我,如果您有任何想法如何解决这个问题。谢谢!