gpt4 book ai didi

PHP 将粗体文本移动到数组键

转载 作者:搜寻专家 更新时间:2023-10-31 20:37:26 25 4
gpt4 key购买 nike

我有详细信息数组:

[info_details] => Array
(
[0] => <b>title:</b> this is title
[1] => <b>name:</b> this is name
[2] => <b>created</b> this is date
)

我需要将这个数组格式化为:

[info_details] => Array
(
[title] => this is title
[name] => this is name
[created] => this is date
)

那么分解粗体文本的最佳方法是什么?我现在的代码:

foreach ( $array as $key => $value ) {
$this->__tmp_data['keep'][] = preg_split('/<b[^>]*>/', $value);
}

但它不起作用。

最佳答案

PHP 具有内置函数 strip_tags()去除 HTML 标签。

   foreach ( $array as $key => $value ) {
$this->__tmp_data['keep'][] = strip_tags($value);
}

更新

<?php
$info_details = array
(
'<b>title:</b> this is title',
'<b>name:</b> this is name',
'<b>created:</b> this is date'
);
$tmp_data = [];
foreach ( $info_details as $key => $value ) {
list($key,$value)=explode('</b>', $value);
$tmp_data['keep'][str_replace(array(':','<b>'),'',$key)] = $value;
}
echo '<pre>';
print_r($tmp_data);

?>

输出

Array
(
[keep] => Array
(
[title] => this is title
[name] => this is name
[created] => this is date
)

)

关于PHP 将粗体文本移动到数组键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31616216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com