scarstens
4/10/2015 - 5:57 PM

Function to use with SimpleXML that allows you to properly encode all XML values, use in an example like $setting->addChild( $name, xml_enti

Function to use with SimpleXML that allows you to properly encode all XML values, use in an example like $setting->addChild( $name, xml_entities($v) );

<?php
//for use with SimpleXML objects
//ie $setting->addChild( $name, xml_entities($v) );
if(!function_exists('xml_entities')) {
	function xml_entities( $string ) {
		return strtr(
			$string,
			array(
				"<" => "&lt;",
				">" => "&gt;",
				'"' => "&quot;",
				"'" => "&apos;",
				"&" => "&amp;",
			)
		);
	}
}