gpt4 book ai didi

PHP:从 array_values() 中的值中剥离标签

转载 作者:可可西里 更新时间:2023-11-01 12:51:55 25 4
gpt4 key购买 nike

我想在使用制表符内爆之前从 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字符串中的标签。)

(不知道你的大功能是什么。)

关于PHP:从 array_values() 中的值中剥离标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4910181/

25 4 0