OK so I completely misunderstood! Answer number 2 here:
$dom = new DOMDocument;
$dom->load('yourdoc.html');// Load document
$inputs = $dom->getElementsByTagName("input"); //Get inputs
for($i=0; $i<$inputs->length; $i++){ // For every input found
$thisName = $inputs->item($i)->getAttribute("name"); // Put the name in a variable
$inputs->item($i)->setAttribute("id",$thisName); // Then set ID as the same
}
$dom->save('yourdoc.html'); //Save the document
This has to be closer to what you want, surely?
No parsers, just some simple DOM work.