Deprecated: Optional parameter $keys declared before required parameter $cms_id is implicitly treated as a required parameter in /home/www/dev/work/class/blog/CmsKey.php on line 75

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$title is deprecated in /home/www/dev/work/website/lvesu/class/controller/blog/php.php on line 28

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$outlink is deprecated in /home/www/dev/work/website/lvesu/template/blog/cms/php.manual.tpl on line 2

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$status is deprecated in /home/www/dev/work/website/lvesu/template/blog/index.head.php on line 2
PHP - Manual: 示例 - 互联网笔记

略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: 示例

2025-04-19

添加备注

用户贡献的备注 2 notes

up
39
Juan Herrera
15 years ago
When using simplexml to access a element the returned object may be a SimpleXMLElement instead of a string.

Example:

<?php
$string
= <<<XML
<?xml version='1.0'?>
<document>
<cmd>login</cmd>
<login>Richard</login>
</document>
XML;


$xml = simplexml_load_string($string);
print_r($xml);
$login = $xml->login;
print_r($login);
$login = (string) $xml->login;
print_r($login);
?>

Expected result:
----------------
SimpleXMLElement Object
(
[cmd] => login
[login] => Richard
)
Richard
Richard

Actual result:
--------------
SimpleXMLElement Object
(
[cmd] => login
[login] => Richard
)
SimpleXMLElement Object
(
[0] => Richard
)
Richard

But this is an intended behavior. See http://bugs.php.net/bug.php?id=29500
up
-4
mike at mike-griffiths dot co dot uk
16 years ago
It is important that you select the correct method of loading the XML in depending on the format of your XML file.

If you use the wrong function to load it in you will get some strange errors.

官方地址:https://www.php.net/manual/en/simplexml.examples.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3