$f = 'a.txt'; file_put_contents("_$f",preg_replace('/(.+?)[:;]{1}(.+?)[\r\n]{0,}/', '$2:$1'."\n", implode('',file($f))));