Récupération de l'encodage d'un url avec Curl
Bonjour,
J'essaye de crawler la page d'un site externe par son url, j'ai fait un bout de code avec curl qui me permet de récupérer le texte HTML d'une page.
de cette sorte en partie...
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| $ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $_url);
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
//curl_setopt ($ch, CURLOPT_COOKIEJAR, "c:\cookie.txt");
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 120);
$code = curl_exec ($ch);
curl_close($ch);
$this->_txt=$code;
//echo $this->_txt; |
Mon unique problème est la différence des Charsets/Encodage (ISO et UFT-8) que je ne sais pas comment récupérer / identifier pour me dire une chose pourtant simple... et qui me fait déchanter...
Si le site indexé utilise un encodage UFT-8, alors indexe sa page sous ce format...
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <?php
If ($charsetdusitevisite = "iso-8859-1" )
{
echo'
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">';
}
else {
echo'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
}
// Mais comment récupérer cette info pour la traiter dans une condition simple ??
?> |
D'avance merci
yule