最近由于项目需要就研究了一下,下面直接上代码
public function fuwen($id = null){ if ($id === null) $this->error('缺少参数'); // dump($id); $nke = Db::name('forum_thread')->where('id',$id)->find(); $content = $nke['content']; preg_match_all('#src="([^"]+?)"#',$content, $the ); $sd = implode(',',$the[1]); $na = Db::name('forum_thread')->where('id',$id)->update(['conimage'=>$sd]); if ($na = 1) { $this->success('编辑成功', 'index'); } else { $this->error('编辑失败'); }
}
其中用到了两个常见的函数 preg_match_all()和implode()函数
这里就简单介绍一下这两个函数,大牛可忽略
implode() 函数返回由数组元素组合成的字符串,这个函数的对头 explode()把字符串打散为数组
preg_match_all()这个函数已经有人介绍了我就直接把人家的链接给拿过来了