Skip to content

Instantly share code, notes, and snippets.

@scarstens
Created April 10, 2015 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scarstens/ba8cd750ca77c78740d2 to your computer and use it in GitHub Desktop.
Save scarstens/ba8cd750ca77c78740d2 to your computer and use it in GitHub Desktop.
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;",
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment