How to access a member of an stdClass in PHP that starts with an @

前端 未结 4 529
不知归路
不知归路 2021-01-04 09:10

I have some json object that I decoded, and one of the attributes starts with an \"@\" and I can\'t access the element with php because it throws an error.

          


        
4条回答
  •  南笙
    南笙 (楼主)
    2021-01-04 09:23

    Try to use,

    $objSimpleXml->attributes()->id
    

    Sample Code to Refer

    
     1
    
    XML;
    
    $xml = simplexml_load_string($string);
    var_dump( $xml );
    foreach($xml->foo[0]->attributes() as $a => $b) {
        echo $a,'="',$b,"\"\n";
    }
    ?> 
    

提交回复
热议问题