php - undefined offset : 1

标签 php html offset

在我当前的 PHP 脚本中出现此错误: undefined offset :1

我的代码在这里:

$query = "SELECT item_id, username, item_content FROM updates ORDER BY update_time DESC                 LIMIT " . $start . ", " . $number_of_posts;

    $result = mysql_query($query) or die(mysql_error());        
    while($row = mysql_fetch_assoc($result)) {
            preg_match("/<p>(.*)<\/p>/",$row['item_content'],$matches);
            $row['item_content'] = strip_tags($matches[1]);
            $posts[] = $row;
        }

如果您知道是什么原因造成的,那么在下面发帖会很有帮助。谢谢! :)

最佳答案

代替

$row['item_content'] = strip_tags($matches[1]);

尝试

if (isset($matches[0]) && isset($matches[0][1]))
  $row['item_content'] = strip_tags($matches[0][1]);
else
  $row['item_content'] = '';

关于php - undefined offset : 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5424236/

相关文章:

php - 如何在 Laravel DB::select 绑定(bind)中转义单引号

php - "Content type"数据库字段

jquery - 如何在 WordPress 站点中制作自定义宽子菜单

javascript - 为什么单击此复选框后无法取消选中?

java - 为什么 java.util.Date 将 Year 表示为 "year-1900"?

php - 从 MySQL 表创建数组

html - 在 flexbox 中,如何将 2 个元素排成一行,将 2 个元素排成一列?

Python:strftime() UTC 偏移量在 Windows 中未按预期工作

Javascript (jQuery) 将图像缩放到其容器的中心点

php - 用 php explode json 中的 key