[Php-it] html entities

Alessandro Marinuzzi alecosnet at inwind.it
Thu Sep 7 14:59:52 CEST 2006


Domenico L. ha scritto:
> Ciao ragazzi ho un problema piuttosto fastidioso:
>    Devo convertire e de convertire tutte i caratteri speciali in 
> entitià html, MA (!) non devo toccare i tag....
>
> cioè da
> per&ograve; è <b>strano</b>!
>
> devo ottnere
>
> per&ograve; &grave; <b>strano</b>!
>
>
> Ciao!
>
Metti: <META HTTP-EQUIV="content-type" 
CONTENT="text/html;CHARSET=ISO-8859-1">
e poi...
usa con PHP4:

$conv = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);
$body = strtr($body, $conv);

poi vai di str_replace così:

$body = str_replace("&lt;", '<', $body);
$body = str_replace("&gt;", '>', $body);


Ciao!

PS: per invertire le entità fai se mai ti dovesse servire:

$conv = array_flip($conv);
$body = strtr($body, $conv);

-- 
Alessandro Marinuzzi
---------------------
http://www.alecos.it/
---------------------



More information about the Php-it mailing list