I'm looping through a database table which holds some data related to external API responses.
Someone was saving the responses as text, like so:
object(stdClass)#5 (1) {
["CreateProspectResult"]=>
object(stdClass)#6 (3) {
["State"]=>
string(7) "Success"
["ErrorMessage"]=>
string(0) ""
["ReturnValue"]=>
object(stdClass)#7 (1) {
["ProspectID"]=>
int(304)
}
}
}
I'm guessing the original developer was doing a var_dump()
with the <pre>
tags, and saved the response literally.
When I loop through the Table results, I'm want to convert the string back into an Object, so I can parse it. Which I'm failing at, badly.
Here's what I've attempted:
<?php
$string = '
object(stdClass)#5 (1) {
["CreateProspectResult"]=>
object(stdClass)#6 (3) {
["State"]=>
string(7) "Success"
["ErrorMessage"]=>
string(0) ""
["ReturnValue"]=>
object(stdClass)#7 (1) {
["ProspectID"]=>
int(304)
}
}
}
';
$xmlObj = simplexml_load_string($string);
echo $xmlObj->CreateProspectResult->State;
?>
PHP isn't enjoying my attempts, and giving me non-object-related errors back.
Is it possible to take such a string and convert it back into an Object?