public function editimg(GuNew $model) { $data = $model::field(['content', 'id'])->order(['id'=>'desc'])->select(); // dump($data); // exit; foreach ($data as $key => $vo) { $pattern = '/<img (.*?)+src=[\'"](.*?)[\'"]/i'; preg_match_all($pattern, $vo['content'], $match); $content = $vo['content']; $vo['content'] = $this->imgedit($match[2],$content); // dump($vo['content']); $vo->save($vo->toArray()); } // dump($data); dump('成功'); } public function imgedit($arr, &$srt) { foreach ($arr as $v) { //判断字符串中是否存在public if(strpos($v,'public')===false){ $srt = str_replace($v, '/public' . $v, $srt); } } return $srt; }