A low-cost and environmental friendly hierarchically porous polymer was used. The polymer with multi-level pores can rapidly remove oils from water selectively. The porous polymer can separate both surfactant-stabilized W/O and O/W emulsions. The porous polymer has high separation efficiency and good reusability.