To remove everything except [] use $txt = eregi_replace("[][]", "", $txt);
Since [] would be everything except empty set of chars, first "]" is not considered as the closing one. Also, inside "[]" block, "[" has no special meaning. Therefore, none of them need backslashes - only their order is important ("]" has to go first).