Skip to content

Instantly share code, notes, and snippets.

@remcotolsma
Created July 3, 2014 12:57
Show Gist options
  • Save remcotolsma/fe1fc0642a083d9eaa8d to your computer and use it in GitHub Desktop.
Save remcotolsma/fe1fc0642a083d9eaa8d to your computer and use it in GitHub Desktop.
XML Security test SimpleXMLElement.
<?php
/**
* Title: XML Security
* Description:
* Copyright: Copyright (c) 2005 - 2014
* Company: Pronamic
* @author Remco Tolsma
* @version 1.0.0
*/
class Pronamic_WP_Pay_XML_Security {
public static function filter( $variable, $filter = FILTER_SANITIZE_STRING ) {
$result = null;
if ( $variable ) {
$result = filter_var( (string) $variable, $filter );
}
return $result;
}
}
$string = <<<XML
<?xml version='1.0'?>
<document>
<title>Forty What?</title>
<from>Joe</from>
<to>Jane</to>
<body>
I know that's the answer -- but what's the question?
</body>
</document>
XML;
$xml = simplexml_load_string($string);
$test = isset( $xml->title );
var_dump( $test );
$title = $xml->title;
$test = isset( $title );
var_dump( $test );
$test = isset( $xml->blub );
var_dump( $test );
$blub = $xml->blub;
$test = isset( $blub );
var_dump( $test );
var_dump( $title );
var_dump( $blub );
$c = count( $title );
var_dump( $c );
$c = count( $blub );
var_dump( $c );
if ( $title ) {
var_dump( $title );
}
if ( $blub ) {
var_dump( $blub );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment