Fix encoding detection for php before 5.4

This should fix the issues with UTF encoded footers and also make the preg_match_all call compatible with php5.3