读取整个数组中的关键字
我一直在研究我的应用程序的关键字检测部分,除了 $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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定你在那里发生了什么,但问题似乎是你的 foreach 循环位于错误的位置。尝试:
Not sure what you have going on there, but the problem seems to be your foreach loop is in the wrong place. Try:
您复制并粘贴了这段代码吗?
第 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?