xanti a dit:je voudrais détecter l'encodage d' un fichier xml (utf-8, iso-8859-1) via un script ou une fonction php, j'ai beau chercher sur la toile, j'ai rien vu d'intéressant, si quelqu’un à un exemple ou une piste pour résoudre mon problème je suis preneur.
# returns 0 if the string is definitely NOT UTF-8
# returns 1 if the string may very well be UTF-8 (but this is not 100% sure)
sub check_utf8
{
my ($word) = @_;
return 0 if (!defined $word);
my (@c) = split //,$word;
my ($c);
while (defined ($c = shift @c))
{
$c = ord $c;
if ($c >= 0xc0 && $c <= 0xdf)
{
$c = ord shift @c;
return 0 if ($c<0x80 || $c >0xbf);
}
elsif ($c >= 0xe0 && $c <= 0xef)
{
$c = ord shift @c;
return 0 if ($c<0x80 || $c >0xbf);
$c = ord shift @c;
return 0 if ($c<0x80 || $c >0xbf);
}
elsif ($c >= 0xf0 && $c <= 0xf7)
{
$c = ord shift @c;
return 0 if ($c<0x80 || $c >0xbf);
$c = ord shift @c;
return 0 if ($c<0x80 || $c >0xbf);
$c = ord shift @c;
return 0 if ($c<0x80 || $c >0xbf);
}
elsif (($c >= 0x80 && $c <=0xbf) || ($c >= 0xf8))
{
return 0;
}
}
return 1;
}
➡️ Offre MyRankingMetrics ⬅️
pré-audit SEO gratuit avec RM Tech (+ avis d'expert)
coaching offert aux clients (avec Olivier Duffez ou Fabien Faceries)
Voir les détails ici