This won't be done efficiently or completely by any computer program... the best way to do it is by hand, by a person.
And... is the CGI in C, Perl, C++ or...?
Perl / C code to PHP is actually really easy, all three languages are astonishingly similar.