Magnetic Fields, Strings and Cosmology