开发者

How to save simplexml node value to string?

开发者 https://www.devze.com 2023-02-13 18:44 出处:网络
I am trying to get a value in a node, and save it into a string variable. I ha开发者_运维问答ven\'t used PHP in about 5 years so I have no idea what is going on?

I am trying to get a value in a node, and save it into a string variable. I ha开发者_运维问答ven'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 .

0

精彩评论

暂无评论...
验证码 换一张
取 消