111';function test($matches){ preg_match_all('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i',$matches[0],$match,PREG_PATTERN_ORDER); $imgList = &$match[0]; if($imgList && is_array($imgList)){ foreach($imgList as &$img){ preg_match('//i', $img, $sub); $url = $sub[1]; $parseUrl = parse_url($url); if(strpos($parseUrl['host'], 'feiniu.com') !== false && !preg_match('/^\/images/', $parseUrl['path'])){ $img = preg_replace('/( )/i', "\${1}_800x0\${2}", $img); } } } return implode("", $imgList);}echo preg_replace_callback('/ /i', "test", $str);