$news_txt = preg_replace('/\[img id\=(.*?)\]/is', $this->Img2Out("$1"), $news_txt); !class this function Img2Out($img_id){ $this->DB("table"); $img_res = mysql_query("SELECT * FROM news_img WHERE img_id='$img_id'"); $ir = mysql_fetch_array($img_res); if(@mysql_num_rows($img_res) == 1) { return "\"\""; } else { return $img_id; } }