- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图显示从我网站的特定部分获取的以逗号分隔的标签。我创建的 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/
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Combination of List> 我有多个列表,可以是 2 个或 3 个,最多 10 个列表,有多个
我是一名优秀的程序员,十分优秀!