Salve esiste una funzione php che fa l'inverso della funzione htmlentities?
Salve esiste una funzione php che fa l'inverso della funzione htmlentities?
Cari amici a quanto pare nn esiste una funzione php ad hoc che fa la conversione inversa della funzione htmlentities().
Visto così ho scritto io una funzione.
Di seguito è riportatata.
Ciao.
$arrayCaratteriSpeciali = array(
" " => "",
"¢" => "¢",
"£" => "£",
"¤" => "¤",
"¥" => "¥",
"¦" => "¦",
"§" => "§",
"¨" => "¨",
"©" => "©",
"ª" => "ª",
"«" => "«",
"¬" => "¬",
"®" => "®",
"¯" => "¯",
"°" => "°",
"±" => "±",
"²" => "²",
"³" => "³",
"´" => "´",
"µ" => "µ",
"¶" => "¶",
"·" => "·",
"¸" => "¸",
"¹" => "¹",
"º" => "º",
"»" => "»",
"¼ "=> "¼",
"½" => "½",
"¾" => "¾",
"¿" => "¿",
"À" => "À",
"Á" => "Á",
"Â" => "Â",
"Ã" => "Ã",
"Ä" => "Ä",
"Å" => "Å",
"Æ" => "Æ",
"Ç" => "Ç",
"È" => "È",
"É" => "É",
"Ê" => "Ê",
"Ë" => "Ë",
"Ì" => "Ì",
"Í" => "Í",
"Î" => "Î",
"Ï" => "Ï",
"Ð" => "Ð",
"Ñ" => "Ñ",
"Ò" => "Ò",
"Ó" => "Ó",
"Ô" => "Ô",
"Õ" => "Õ",
"Ö" => "Ö",
"×" => "×",
"Ø" => "Ø",
"Ù" => "Ù",
"Ú" => "Ú",
"Û" => "Û",
"Ü" => "Ü",
"Ý" => "Ý",
"Þ" => "Þ",
"ß" => "ß",
"à"=> "à",
"á" => "á",
"â" => "â",
"ã" => "ã",
"ä" => "ä",
"å" => "å",
"æ" => "æ",
"ç" => "ç",
"è" => "è",
"é" => "é",
"ê" => "ê",
"ë" => "ë",
"ì" => "ì",
"í" => "í",
"î" => "î",
"ï" => "ï",
"ð" => "ð",
"ñ" => "ñ",
"ò" => "ò",
"ó" => "ó",
"ô" => "ô",
"õ" => "õ",
"ö" => "ö",
"÷" => "÷",
"øv" => "ø",
"ù" => "ù",
"ú" => "ú",
"û" => "û",
"ü" => "ü",
"ý" => "ý",
"þ" => "þ",
"ÿ" => "ÿ",
"\"" => """,
"&" => "&",
"<" => "<",
">" => ">",
"€" => "€",
"ˆ" => "ˆ",
"˜" => "˜",
"…" => "…",
"™" => "™");
/*
* la funzione prende in input una stringa contenente caratteri
* Ascii e ritorna una nuova stringa il corrispondente carattere associato agli ascii
* trovati
*/
function eliminaAscii($s){
global $arrayCaratteriSpeciali;
$stringa = $s;
foreach($arrayCaratteriSpeciali as $carattere => $ascii){
$temp = explode($ascii,$stringa);
$len = count($temp);
if($len > 1){
$nuovaStringa = "";
for($i=0;$i<$len;$i++){
if($i == 0)
$nuovaStringa = $temp[$i];
else
$nuovaStringa .= $carattere.$temp[$i];
}
$stringa = $nuovaStringa;
}
}
return $stringa;
}
un piccolo copia/incolla dal manuale PHP:
Convert all HTML entities to their applicable characters (PHP 4 >= 4.3.0, PHP 5)
string html_entity_decode ( string string [, int quote_style [, string charset]] )
html_entity_decode() is the opposite of htmlentities() in that it converts all HTML entities to their applicable characters from string.