$xml =<<< XML
<MCS-ENVELOPE type='noteRequest' detail='onlyTitle' username='001' password='' fileID='1'> </MCS-ENVELOPE>
XML;$x = simplexml_load_string($xml);
print_r($x);out:
SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [type] => noteRequest
            [detail] => onlyTitle
            [username] => 001
            [password] => 
            [fileID] => 1
        )    [0] =>  
)

解决方案 »

  1.   

    <?php
    $string = <<< XML
    <MCS-ENVELOPE type='noteRequest' detail='onlyTitle' username='001' password='' fileID='1'> 
    </MCS-ENVELOPE>
    XML;$xml = simplexml_load_string($string); foreach($xml->attributes() as $name => $value) {
        echo $name,'="',$value,"\"\n";
    }
    ?>
      

  2.   

    学习一下
    没用过simplexml_load_string
      

  3.   

    他的那个<<<中间有空格
      

  4.   

    应该不是空格的问题啦!我把空格去掉还是有错咯!再请帮忙啊!小弟才学PHP两天!真的不会啊!谢谢了!
      

  5.   

    <?php 
    $str = <<<XML
        <MCS-ENVELOPE type='noteRequest' detail='onlyTitle' username='001' password='' fileID='1'> 
        </MCS-ENVELOPE>
    XML;
    $xml = simplexml_load_string($str); 
    print_r($xml); 
    ?>
    有空去手册查查<<<这个符号是什么.
      

  6.   

    空格不是我的错,csdn硬加上的
    其实
    $xml = "<MCS-ENVELOPE type='noteRequest' detail='onlyTitle' username='001' password='' fileID='1'> </MCS-ENVELOPE> 
    ";
    是一样的
    simplexml_load_string 需要php5环境
    非win32环境需要安装 simplexml 扩展
      

  7.   

    我按12楼的方法试了一下咯!现在提示没有simplexml_load_string函数的定义!可能是环境问题吧!
    唉!我该怎么办啊!都在催我啊!!!
    什么是PHP5环境!?我如何安装simplexml扩展!
      

  8.   

    simplexml_load_string 函数好像处理不了xml里带类似 &nbsp; 这样的字符
      

  9.   

    手册有解释,simplexml_load_string中的第一个参数data是A well-formed XML string,可是webservice传过来的data是个标准的string,需要通过webservice传递<root>...</root>中间部分内容,然后
    $data = <<<XML
    <?xml varsion='1.0'?>$data
    XML;
    这样处理下,现在就可以正常使用
    simplexml_load_string($data)
    了。