if(preg_match_all("/\[code=([^\[]*)](.+?)\[\/code]/is", $txt, $cod)){ for ($i = 0; $i < sizeof($cod[0]); $i++) { $txt = str_replace($cod[0][$i], '', $txt); } }