Re: PHP5 simpleXML bug or am i just being silly :)
| From: | William Bailey | Date: | Fri, 27 Feb 2004 09:40:47 +0000 |
| Subject: | Re: PHP5 simpleXML bug or am i just being silly :) | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-178994@lists.php.net to get a copy of this message | ||
OK sonce the php example code attachment go nuked here it is...
[[::PHP START::]]
<?php
header('Content-type: text/plain');
$xmlstr = '<?xml version="1.0"?>
<access>
<user>
<login>user1</login>
<password>letMeIn</password>
<site>www.pro-net.co.uk</site>
<site>www.example.com</site>
</user>
<user>
<login>user2</login>
<password>myPassword</password>
<site>www.pro-net.co.uk</site>
</user>
</access>';
$nl = "\r\n";
$xml = simplexml_load_string($xmlstr);
print('Current PHP version is : '.phpversion().$nl.$nl);
print('$xml is:'.$nl);
print_r($xml);
print($nl.$nl);
// Test authentication to get the correct user information
$login = 'user1';
$password = 'letMeIn';
print($nl.$nl.'Trying to authenticate "'.$login.'" with password "'.$password.'".'.$nl.$nl);
$isAuth = false;
foreach($xml->user as $user){
if(utf8_decode($user->login) == $login && utf8_decode($user->password) == $password){
$isAuth = true;
break;
}
}
if(!$isAuth){
print($nl.$nl.'Invalid User.'.$nl);
die();
}
// So lets output the variables to see what we have...
print('$user is:'.$nl);
print_r($user);
print($nl.$nl);
print('$user->site is:'.$nl);
print_r($user->site);
print($nl.$nl);
print('$user->site[0] is:'.$nl);
print_r($user->site[0]);
print($nl.$nl);
?>
[[::PHP END::]]
William Bailey wrote:
To follow up my question from yesterday i have made a test script that will produce the problem that i am seeing. The attached script will produce the following output on both my windows box (which runs a 2 day old php5 snapshot) and my FreeBSD box which uses a version out of the ports. The php version below is from the freeBSD installation... [[::OUTPUT START::]] Current PHP version is : 5.0.0a4-alexdupre $xml is: simplexml_element Object ([user] => Array ( [0] => simplexml_element Object ( [login] => user1 [password] => letMeIn [site] => Array ( [0] => www.pro-net.co.uk [1] => www.example.com ))[1] => simplexml_element Object ( [login] => user2 [password] => myPassword [site] => www.pro-net.co.uk ))) Trying to authenticate "user1" with password "letMeIn". $user is: simplexml_element Object ([login] => user1 [password] => letMeIn [site] => Array ( [0] => www.pro-net.co.uk [1] => www.example.com )) $user->site is: Array ([0] => simplexml_element Object ( )[1] => simplexml_element Object ( )) $user->site[0] is: simplexml_element Object ( ) [[::OUTPUT END::]]