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
[EMAIL PROTECTED]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to