未定义的偏移量:1 [英] Undefined offset: 1

查看:160
本文介绍了未定义的偏移量:1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我当前的PHP脚本中出现这个错误:Undefined offset:1



我的代码在这里:

  $ query =选择item_id,用户名,item_content从更新ORDER BY update_time DESC LIMIT。 $开始。 ,。 $ number_of_posts; 

$ result = mysql_query($ query)或die(mysql_error());
while($ row = mysql_fetch_assoc($ result)){
preg_match(/< p>(。*)< \ / p> /,$ row ['item_content'], $匹配);
$ 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'] ='';


In my current PHP script this error comes up: Undefined offset: 1

My code is here:

$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;
        }

If you see whats causing this, posting below would really help. Thanks! :)

解决方案

Instead of

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

Try

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

这篇关于未定义的偏移量:1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆