gpt4 book ai didi

php - PHP 结果中的未知数组

转载 作者:行者123 更新时间:2023-11-29 00:21:32 24 4
gpt4 key购买 nike

我试图显示从我网站的特定部分获取的以逗号分隔的标签。我创建的 PHP 函数是:

$fid = intval($fid);
$query = $db->query("
SELECT p.message
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON(t.firstpost=p.pid)
WHERE p.fid = '{$fid}'
");
$audio_tags_bit = '';
while($p = $db->fetch_array($query))
{
$audio_tags_bit .= $p['message'];
}

$keys = get_tags($audio_tags_bit);
foreach($keys as $key)
{
$keys .= $key.', ';
}
$keys = substr($keys,0,strlen($keys)-2);


function get_tags($str)
{
$keywords = array();
$str=utf8_decode($str);

//clean string from html/bbcode
$str = html_entity_decode($str);
$str = strip_tags($str);
$str = preg_replace('#\[(.*?)\]#','',$str);

//replace - with space
$str = preg_replace('#-#',' ',$str);

//string in lowcase
$str = strtolower($str);



//clean string //only a-zA-Z0-9 and spaces
$str = preg_replace('#[^a-zA-Z0-9\s]#','',$str);



//split by whitespace
$splits = preg_split('#\s+#',$str);

foreach($splits as $key)
{

$key=trim($key);
if($key=="" || strlen($key) < 4 || is_numeric($key) || isset($forbidden[$key])) continue;
if(!isset($keywords[$key]))
{
$keywords[$key] = 1;
}
else
{
$keywords[$key]++;
}
}
//sort, reverse
asort($keywords);
$keywords = array_reverse($keywords);
$tmpkeywords = array_keys(array_slice($keywords,0,$max));
$keywords = array();
foreach($tmpkeywords as $key)
{
array_push($keywords,$key);
}
return $keywords;
}

但是它显示的结果是:

Arrayquid, carum, finem, quasi, ille, sapiens, itaque, semper, constructio, interrete, vacabit, reges, verum, etiam, quemque, sibi, quae, dixisset, modo, aiat, neget, elit, hanc, adipiscing, consectetur, ipsum, dolor, amet, ergo, intuens, curem, lorem, absolvere, signum, debet, institutum, illud, vehementer, esse, vexat, immo, 更多, stoicorum, enim, ista, lenius, alio, genere, maxime, natura, vellet, erat, satis, nondum, autem, explanatum, aliquando, faciamus, redderet, sextus, peducaeus, fortasse, epicurus, quidem, reddes, ipse, censes, latino, paucis, haec, additis, requiras, quod、fore、igitur、inquit

注意结果开头的 Array。它来自哪里?我希望结果应该是这样的:

quid, carum, finem, quasi, ille, sapiens, itaque, semper, constructio, interrete, vacabit, reges, verum, etiam, quemque, sibi, quae, dixisset, modo, aiat, neget, elit, hanc, adipiscing, consectetur, ipsum, dolor, amet, ergo, intuens, curem, lorem, absolvere, signum, debet, institutum, illud, vehementer, esse, vexat, immo, 更多, stoicorum, enim, ista, lenius, alio, genere, maxime, natura, vellet, erat, satis, nondum, autem, explanatum, aliquando, faciamus, redderet, sextus, peducaeus, fortasse, epicurus, quidem, reddes, ipse, censes, latino, paucis, haec, additis, requiras, quod、fore、igitur、inquit

Array 不应该存在。请帮忙

最佳答案

改变这个:

$keys = get_tags($audio_tags_bit);
foreach ($keys as $key) {
$keys .= $key.', ';
}

为此:

$keywords = get_tags($audio_tags_bit);
foreach ($keywords as $key) {
$keys .= $key.', ';
}

您实际上在 foreach 循环中分配了与用于获取结果的变量相同的变量

关于php - PHP 结果中的未知数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20848662/

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