Re: actually the è not the ampersand

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



jonathan wrote:
so, the problem isn't the ampersand but rather the &egrave; in the following: <item_name>farm lettuces with reed avocado, cr&egrave;me fra&icirc;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 (
		"/&quot;/",
		"/&amp;/",
		"/&lt;/",
		"/&gt;/",
		"/&nbsp;/",
		"/&iexcl;/",
		"/&cent;/",
		"/&pound;/",
		"/&curren;/",
		"/&yen;/",
		"/&brvbar;/",
		"/&sect;/",
		"/&uml;/",
		"/&copy;/",
		"/&ordf;/",
		"/&laquo;/",
		"/&not;/",
		"/&shy;/",
		"/&reg;/",
		"/&macr;/",
		"/&deg;/",
		"/&plusmn;/",
		"/&sup2;/",
		"/&sup3;/",
		"/&acute;/",
		"/&micro;/",
		"/&para;/",
		"/&middot;/",
		"/&cedil;/",
		"/&sup1;/",
		"/&ordm;/",
		"/&raquo;/",
		"/&frac14;/",
		"/&frac12;/",
		"/&frac34;/",
		"/&iquest;/",
		"/&Agrave;/",
		"/&Aacute;/",
		"/&Acirc;/",
		"/&Atilde;/",
		"/&Auml;/",
		"/&Aring;/",
		"/&AElig;/",
		"/&Ccedil;/",
		"/&Egrave;/",
		"/&Eacute;/",
		"/&Ecirc;/",
		"/&Euml;/",
		"/&Igrave;/",
		"/&Iacute;/",
		"/&Icirc;/",
		"/&Iuml;/",
		"/&ETH;/",
		"/&Ntilde;/",
		"/&Ograve;/",
		"/&Oacute;/",
		"/&Ocirc;/",
		"/&Otilde;/",
		"/&Ouml;/",
		"/&times;/",
		"/&Oslash;/",
		"/&Ugrave;/",
		"/&Uacute;/",
		"/&Ucirc;/",
		"/&Uuml;/",
		"/&Yacute;/",
		"/&THORN;/",
		"/&szlig;/",
		"/&agrave;/",
		"/&aacute;/",
		"/&acirc;/",
		"/&atilde;/",
		"/&auml;/",
		"/&aring;/",
		"/&aelig;/",
		"/&ccedil;/",
		"/&egrave;/",
		"/&eacute;/",
		"/&ecirc;/",
		"/&euml;/",
		"/&igrave;/",
		"/&iacute;/",
		"/&icirc;/",
		"/&iuml;/",
		"/&eth;/",
		"/&ntilde;/",
		"/&ograve;/",
		"/&oacute;/",
		"/&ocirc;/",
		"/&otilde;/",
		"/&ouml;/",
		"/&divide;/",
		"/&oslash;/",
		"/&ugrave;/",
		"/&uacute;/",
		"/&ucirc;/",
		"/&uuml;/",
		"/&yacute;/",
		"/&thorn;/",
		"/&yuml;/"
	);
	$replace_array = array (
		'&#034;',
		'&#038;',
		'&#060;',
		'&#062;',
		'&#160;',
		'&#161;',
		'&#162;',
		'&#163;',
		'&#164;',
		'&#165;',
		'&#166;',
		'&#167;',
		'&#168;',
		'&#169;',
		'&#170;',
		'&#171;',
		'&#172;',
		'&#173;',
		'&#174;',
		'&#175;',
		'&#176;',
		'&#177;',
		'&#178;',
		'&#179;',
		'&#180;',
		'&#181;',
		'&#182;',
		'&#183;',
		'&#184;',
		'&#185;',
		'&#186;',
		'&#187;',
		'&#188;',
		'&#189;',
		'&#190;',
		'&#191;',
		'&#192;',
		'&#193;',
		'&#194;',
		'&#195;',
		'&#196;',
		'&#197;',
		'&#198;',
		'&#199;',
		'&#200;',
		'&#201;',
		'&#202;',
		'&#203;',
		'&#204;',
		'&#205;',
		'&#206;',
		'&#207;',
		'&#208;',
		'&#209;',
		'&#210;',
		'&#211;',
		'&#212;',
		'&#213;',
		'&#214;',
		'&#215;',
		'&#216;',
		'&#217;',
		'&#218;',
		'&#219;',
		'&#220;',
		'&#221;',
		'&#222;',
		'&#223;',
		'&#224;',
		'&#225;',
		'&#226;',
		'&#227;',
		'&#228;',
		'&#229;',
		'&#230;',
		'&#231;',
		'&#232;',
		'&#233;',
		'&#234;',
		'&#235;',
		'&#236;',
		'&#237;',
		'&#238;',
		'&#239;',
		'&#240;',
		'&#241;',
		'&#242;',
		'&#243;',
		'&#244;',
		'&#245;',
		'&#246;',
		'&#247;',
		'&#248;',
		'&#249;',
		'&#250;',
		'&#251;',
		'&#252;',
		'&#253;',
		'&#254;',
		'&#255;'
	);
$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@xxxxxxxxxxxx

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux