|
Posted by John Nichel on 10/13/05 00:17
jonathan wrote:
> so, the problem isn't the ampersand but rather the è in the
> following:
> <item_name>farm lettuces with reed avocado, crème fraîche,
> radish and cilantro</item_name>
>
> I'm not sure how php / DOM handles these non-standard other entities.
> How would / could I escape this? do I need to convert it to something
> else to make DOM happy (say grave) and then convert it back when
> outputted? It seems like there might be a way to use
> createEntityReference but searching through google shows no examples.
> arg.....
I have to do this to create XML documents for our company, and built
this function for it. You're welcome to use/modify it to fit your needs.
function convertString ( $string ) {
$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
ÜberGeek
KegWorks.com
716.856.9675
john@kegworks.com
[Back to original message]
|