简体   繁体   中英

How to save simplexml node value to string?

I am trying to get a value in a node, and save it into a string variable. I haven't used PHP in about 5 years so I have no idea what is going on?

string $errorMessage = (string)$error->message);
print_r($errorMessage);

returns nothing

first do

$errorMessage = (string)$error->message;

and dont do print_r its used for echoing array simply use echo instead so

echo $errorMessage;

Php is not strongly typed language so you dont need to do string $errorMessage; , but still casting is pressent in php , coz objects such as simplexml implements __toString magic function which gets called automaticaly when you cast that object as string .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM