Converting HTMLentities to numeric format in PHP
Translation of the original in Catalan. Read it in: CatalàCastellano
Some time ago I had a little problem in PHP that I reported to the Comesfa? list but I did not manage to make any sense of it, the problem was the following: (original mail)
From: Oriol Rius
To: comesfa@guifi.net
Subject: Pregunta pels PHPerus!!!
Date: Tue, 29 Jun 2004 09:14:16 +0200
Hola nanos, aquest finde m'he passat unes quantes hores programant en
PHP fent un connector per la itnerficie XMLRPC dels blogs. Bé és igual,
ja ús explicaré. El problema és que m'he passat més de 4h buscant com
convertir això:
Característiques
a
Característiques o Característiques
i no he tingut collons de fer-ho... HELP!!!!!!!!!!!!!!!!!
A veure si algú sap com fer-ho, gràcies.
Salutacions,
Oriol.
So the other day, looking for something completely unrelated, I found the solution in the PHP online manual itself, here is the little piece of magic code, which solves the problem mentioned above:
function unhtmlentities ($string) {
$trans_tbl = get_html_translation_table (HTML_ENTITIES);
$trans_tbl = array_flip ($trans_tbl);
$ret = strtr ($string, $trans_tbl);
return preg_replace('/&#(d+);/me',
"chr('1')",$ret);
}