如何通过输入关键字推送出相关文章呢?
我知道select是二维数组,跟
$arr = array( array( 'title' => '测试', 'description' => '测试内容', 'picUrl' => 'https://ssl.demenk.com/dyxcx/public/upload/default/20180822/3b15071c8e7f64d7edb1951acb692628.png', 'url' => 'http://www.baidu.com', ), array( 'title' => '测试111111111', 'description' => '测试内容111111111', 'picUrl' => 'https://ssl.demenk.com/dyxcx/public/upload/default/20180822/a1e6d5575189994988a8c169eff67191.jpg', 'url' => 'http://www.taobao.com', ), array( 'title' => '测试22222222', 'description' => '测试内容222222', 'picUrl' => 'https://ssl.demenk.com/dyxcx/public/upload/default/20180822/2ff3ce26c9233d179ff0184708f56137.jpg', 'url' => 'http://www.zhihu.com', ), );
很像。
请问是把
$postObj->Content
变成
$keywords = $postObj->Content;
这样吗?
我的逻辑是这样写的:
$keywords = $postObj->Content; if(strtolower($postObj->MsgType)== 'text' && trim($postObj->Content) == 'tuwen1'){ $map['content']=['LIKE','%'.$keywords.'%']; $res = DB::name('article')->where($map)->select(); $toUser = $postObj->FromUserName; $fromUser = $postObj->ToUserName; $template = "<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <ArticleCount>".count(5)."</ArticleCount> <Articles>"; foreach($res as $k=>$v){ $template .=" <item> <Title><![CDATA[".$v['title']."]]></Title> <Description><![CDATA[".$v['description']."]]></Description> <PicUrl><![CDATA[".$v['picUrl']."]]></PicUrl> <Url><![CDATA[".$v['url']."]]></Url> </item>"; } $template .="</Articles></xml>"; echo sprintf($template, $toUser, $fromUser, time(), 'news');
可是还是报错,,,有大佬知道如何写吗?十分感谢。