Per quale motivo usi tutto quel codice invece di un semplice:

Codice PHP:
$paginahtml file_get_contents($nomefile);