读取整个数组中的关键字

发布于 2024-12-15 03:47:02 字数 1352 浏览 0 评论 0原文

我一直在研究我的应用程序的关键字检测部分,除了 $msg 之外,一切似乎都工作得很好,我只能让它读取一个结果,即第一条消息。

我试图让它读取整个数组。

如果我执行 var_dump 结果就在那里,我只是不确定如何读取数组。

try {
        $me = $facebook->api('/me');
        $fql    =   "SELECT message FROM status WHERE uid= me()";
        $param  =   array(
                          'method'    => 'fql.query',
                          'query'     => $fql,
                          'callback'  => ''
                          );
        $fqlResult   =   $facebook->api($param);}   
        } catch (FacebookApiException $e) {
        }
          foreach($fqlResult as $row){
                $abt = strtolower($row['about_me']);
                $qts = strtolower($row['quotes']);
                $msg = strtolower($row['message']);//This one is causing trouble!
                $cursewrds = $abt . $msg . $qts . $status;
                $keywords = array("test","curse","words);
                $regex ="/(". implode('|', $keywords) .")/";
                $total = (preg_match_all( $regex, $cursewrds, &$matches));

这是我对 $msg 进行 fql 查询时数组的样子。

[
  {
    "message": "test 1"
  },
  {
    "message": "test 2"
  }, 
  {
    "message": "test 3"
  },
  {
    "message": "test 4"
  }
]

PS 我不是 php 最好的,但如果我在这里,我已经尝试了我能想到的一切。

I've been working on a keyword detection portion of my app and it all seems to be working great except for $msg I can only get it to read one result which is the very first message.

I'm trying to get it to read through the entire array.

If I do a var_dump the results are there, I'm just not sure how to read through the array.

try {
        $me = $facebook->api('/me');
        $fql    =   "SELECT message FROM status WHERE uid= me()";
        $param  =   array(
                          'method'    => 'fql.query',
                          'query'     => $fql,
                          'callback'  => ''
                          );
        $fqlResult   =   $facebook->api($param);}   
        } catch (FacebookApiException $e) {
        }
          foreach($fqlResult as $row){
                $abt = strtolower($row['about_me']);
                $qts = strtolower($row['quotes']);
                $msg = strtolower($row['message']);//This one is causing trouble!
                $cursewrds = $abt . $msg . $qts . $status;
                $keywords = array("test","curse","words);
                $regex ="/(". implode('|', $keywords) .")/";
                $total = (preg_match_all( $regex, $cursewrds, &$matches));

Heres what the array looks like when I do a fql query for $msg.

[
  {
    "message": "test 1"
  },
  {
    "message": "test 2"
  }, 
  {
    "message": "test 3"
  },
  {
    "message": "test 4"
  }
]

P.S. I'm not the best at php but if I'm here I've tried everything I can think of.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如何视而不见 2024-12-22 03:47:02

不确定你在那里发生了什么,但问题似乎是你的 foreach 循环位于错误的位置。尝试:

foreach($fqlResult as $row){
     $abt = strtolower($row['about_me']);
     $qts = strtolower($row['quotes']);
     $msg = strtolower($row['message']);//This one is causing trouble!
     $cursewrds = $abt . $msg . $qts . $status;
     $keywords = array("test","curse","words);
     $regex ="/(". implode('|', $keywords) .")/";
     $total = (preg_match_all( $regex, $cursewrds, &$matches));

     $messages[] = $msg;    
}

Not sure what you have going on there, but the problem seems to be your foreach loop is in the wrong place. Try:

foreach($fqlResult as $row){
     $abt = strtolower($row['about_me']);
     $qts = strtolower($row['quotes']);
     $msg = strtolower($row['message']);//This one is causing trouble!
     $cursewrds = $abt . $msg . $qts . $status;
     $keywords = array("test","curse","words);
     $regex ="/(". implode('|', $keywords) .")/";
     $total = (preg_match_all( $regex, $cursewrds, &$matches));

     $messages[] = $msg;    
}
调妓 2024-12-22 03:47:02

您复制并粘贴了这段代码吗?

第 9 行末尾有一个额外的右大括号。

也许您移动了 foreach 语句,但现在您没有正确终止它,这就是为什么您只获得 foreach 循环的一次迭代?

You copied and pasted this code?

There is an extra closing curly brace at the end of line 9.

Perhaps you moved the foreach statement and now you are not terminating it properly and that is why you are only getting one iteration of the foreach loop?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文