public function update_product_content(){ $wherePro = array(); $orderPro = "px desc,id desc"; $indexprolist = M('product')->where($wherePro)->field("id,content")->order($orderPro)->select(); foreach($indexprolist as $k=>$v){ preg_match_all("/]+>/isU",$v['content'],$matches); if(!empty($matches)) { //注意,上面的正则表达式说明src的值是放在数组的第三个中 $img = $matches[2]; }else { $img = ""; } if (!empty($img)) { $patterns= array(); $replacements = array(); foreach($img as $imgItem){ $replacements[] = "/data/upload/20231010/6524e38e24f36.jpg"; $img_new = "/".preg_replace("/\//i","\/",$imgItem)."/"; $patterns[] = $img_new; } //让数组按照key来排序 ksort($patterns); ksort($replacements); //替换内容 $v['content'] = preg_replace($patterns, $replacements, $v['content']); //test($vote_content); M('product')->save($v); } } echo "success"; }