content, $matches, PREG_SET_ORDER); foreach ($matches as $match) { // 解析属性键值对 preg_match_all('/(\w+)\s*=\s*(["\'])((?:\\\2|(?!\2).)*?)\2/', $match[1], $attributes, PREG_SET_ORDER); $item = array(); $category = ''; // 提取属性并处理转义 foreach ($attributes as $attr) { $key = strtolower($attr[1]); $value = htmlspecialchars_decode(stripslashes($attr[3])); if ($key === 'category') { $category = trim($value); } else { $item[$key] = $value; } } // 设置默认分类 $category = !empty($category) ? $category : '好物分享'; // 保证字段完整性 foreach ($expectedKeys as $key) { if (!isset($item[$key])) { $item[$key] = ''; } } // 过滤多余字段 $item = array_intersect_key($item, array_flip($expectedKeys)); // 组织数据 if (!isset($categories[$category])) { $categories[$category] = array(); } $categories[$category][] = $item; } $this->need('components/header.php'); ?> title() ?> fields->abstract ?> $items): ?> ' . $item['type'] . '' ?> 留言 need('components/comments.php'); ?> need('components/footer.php'); ?>