Created
July 3, 2014 12:57
-
-
Save remcotolsma/fe1fc0642a083d9eaa8d to your computer and use it in GitHub Desktop.
XML Security test SimpleXMLElement.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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