note 107463 added to function.simplexml-load-string

From: Date: Fri, 10 Feb 2012 16:28:59 +0000
Subject: note 107463 added to function.simplexml-load-string
Groups: php.notes 
Request: Send a blank email to php-notes+get-186057@lists.php.net to get a copy of this message
when using an simplexml_load_string and getting an ID and equate it with an integer does not return TRUE, hence the ID is still an OBJECT. Type casting an Object ID will also remove leading zeros and therefore cannot equate with the Object ID reference and return to FALSE. for Example: <?php /** * @author reynaldoahipolito * @copyright 2012 */ $response_xml = "this is the reponse xml"; $xml = simplexml_load_string($response_xml); //ex: xml response for ID == 0012345 if ($xml->attributes()->id == 0012345) { //will return FALSE; } //if we typecast it to integer $id = (int) $xml->attributes()->id; if ($id == 0012345) { //will still return false, hence PHP will removed leading zero when casting it into integer. } if ($id == 12345) { //will return to true since PHP already remove the leading zeros of the ID when casting it. } //heres how to solve it. just make the Object ID into string. the Object ID will equate to ID string. if ($xml->attributes()->id == '0012345') { // will return to TRUE. } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 112.202.59.107 ---- Manual Page -- http://www.php.net/manual/en/function.simplexml-load-string.php Edit -- https://master.php.net/note/edit/107463 Del: integrated -- https://master.php.net/note/delete/107463/integrated Del: useless -- https://master.php.net/note/delete/107463/useless Del: bad code -- https://master.php.net/note/delete/107463/bad+code Del: spam -- https://master.php.net/note/delete/107463/spam Del: non-english -- https://master.php.net/note/delete/107463/non-english Del: in docs -- https://master.php.net/note/delete/107463/in+docs Del: other reasons-- https://master.php.net/note/delete/107463 Reject -- https://master.php.net/note/reject/107463 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186057) next »