| Variante compatible php<4.0.6 | | De Eric Vidal - Vendredi 5 Avril 2002 à 17:05
array_map n'étant disponible que depuis la v4.06, je proposerais la variante suivante, certes moins élégante :
//convertit un texte html en texte normal (compatible PHP<4.0.6)
function htm2txt($text)
{
// Crée un tableau contenant les codes ascii des caractères
// ayant un codage en html
$ascii_array=array_merge(array(34,38,60,62),range(160,255));
// Crée un tableau contenant les caractères correspondants
// aux codes ascci précédents
for ($i=0;$i<count($ascii_array);$i++) {
$chars_array[$i]=chr($ascii_array[$i]);
}
// Crée un tableau contenant les mêmes caractères au format html
for ($i=0;$i<count($chars_array);$i++) {
$html_array[$i]=htmlentities($chars_array[$i]);
}
// Remplace les codes html par leurs équivalents txt dans le texte
for($i=0; $i<count($ascii_array); $i++)
{
$text=ereg_replace($html_array[$i],$chars_array[$i],$text);
}
// Remplace les sauts de ligne html <br> par \n dans le texte
$text=ereg_replace("<br>","\n",$text);
// Supprime les éventuelles balises html et php
$text=strip_tags($text);
// Retourne le texte traité
return($text);
}
|
|