We investigated experimentally and theoretically an invertible fiber-type transformation from a photonic bandgap fiber into a nonideal waveguide and then into an index-guiding photonic crystal fiber via the thermo-optic effect of the fluid filled in the air holes. Such a transformation could be used to develop an in-fiber optical switch/attenuator with a high-extinction ratio of more than 35 dB over an extremely broad wavelength range from 600 to 1700 nm via a small temperature adjustment.