Re: Cleaning bad characters from var

From: Date: Fri, 21 Jul 2006 19:52:56 +0000
Subject: Re: Cleaning bad characters from var
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-239691@lists.php.net to get a copy of this message
Paul Nowosielski wrote:
Dear All, I'm trying to set up an XML feed form our news articles. My XML is validating. The issue is some of the articles have a weird encoding.
I wrote a function to do this for our product descriptions when sending them in a XML doc to certain vendors. It's old, crude, but you're welcome to it. function convertString ( $string, $reverse = false ) { $find_array = array ( "/"/", "/&/", "/</", "/>/", "/ /", "/¡/", "/¢/", "/£/", "/¤/", "/¥/", "/¦/", "/§/", "/¨/", "/©/", "/ª/", "/«/", "/¬/", "/­/", "/®/", "/¯/", "/°/", "/±/", "/²/", "/³/", "/´/", "/µ/", "/¶/", "/·/", "/¸/", "/¹/", "/º/", "/»/", "/¼/", "/½/", "/¾/", "/¿/", "/À/", "/Á/", "/Â/", "/Ã/", "/Ä/", "/Å/", "/Æ/", "/Ç/", "/È/", "/É/", "/Ê/", "/Ë/", "/Ì/", "/Í/", "/Î/", "/Ï/", "/Ð/", "/Ñ/", "/Ò/", "/Ó/", "/Ô/", "/Õ/", "/Ö/", "/×/", "/Ø/", "/Ù/", "/Ú/", "/Û/", "/Ü/", "/Ý/", "/Þ/", "/ß/", "/à/", "/á/", "/â/", "/ã/", "/ä/", "/å/", "/æ/", "/ç/", "/è/", "/é/", "/ê/", "/ë/", "/ì/", "/í/", "/î/", "/ï/", "/ð/", "/ñ/", "/ò/", "/ó/", "/ô/", "/õ/", "/ö/", "/÷/", "/ø/", "/ù/", "/ú/", "/û/", "/ü/", "/ý/", "/þ/", "/ÿ/" ); $replace_array = array ( '"', '&', '<', '>', ' ', '¡', '¢', '£', '¤', '¥', '¦', '§', '¨', '©', 'ª', '«', '¬', '­', '®', '¯', '°', '±', '²', '³', '´', 'µ', '¶', '·', '¸', '¹', 'º', '»', '¼', '½', '¾', '¿', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', '×', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'Þ', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', '÷', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ', 'ÿ' ); $string = htmlentities ( strip_tags ( preg_replace ( "/\n|\r|\r\n/", " ", $string ) ), ENT_QUOTES ); $string = preg_replace ( $find_array, $replace_array, $string ); return $string; } -- John C. Nichel IV Programmer/System Admin (ÜberGeek) Dot Com Holdings of Buffalo 716.856.9675 jnichel@dotcomholdingsofbuffalo.com

« previous php.general (#239691) next »