Web 2.0 Developer & PHP Programmer (ZCE)
May 15, 2009

Rimuovere le entità HTML (unhtmlentities)

Ecco un modo veloce per rimuovere tutte le entità html da una stringa:
function unhtmlentities($string) {
	$string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
	$string = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $string);
	$trans_tbl = get_html_translation_table(HTML_ENTITIES);
	$trans_tbl = array_flip($trans_tbl);
	return strtr($string, $trans_tbl);
}
questa funzione sostituisce sia le entità numeriche che quelle testuali.

Bookmarks: bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Nessun commento

© Copyright 2008 - 2010 Fabio Cicerchia. Powered by Fluxy Framework using the theme bbv1 (customized by Fabio Cicerchia).