Trovata!
function fixQuotes($s){
$q = """;
if (!stristr($s,"=")) return $s;
$out = $s;
preg_match_all("|=(.*)|",$s,$o,PREG_PATTERN_ORDER);
for ($i = 0; $i< count ($o[1]); $i++) {
$t = trim ( $o[1][$i] ) ;
$lc="";
if ($t!="") {
if ($t[strlen($t)-1]==">") {
$lc= ($t[strlen($t)-2].$t[strlen($t)-1])=="/>" ? "/>" : ">" ;
$t=substr($t,0,-1);
}
//missing " or ' at the beginning
if (($t[0]!=""")&&($t[0]!="'")) $out = str_replace( $t, """.$t,$out); else $q=$t[0];
//missing " or ' at the end
if (($t[strlen($t)-1]!=""")&&($t[strlen($t)-1]!="'")) $out = str_replace( $t.$lc, $t.$q.$lc,$out);
}
}
return $out;
}