Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 Posts

    value from simplexml?

    I have a variable which when dumped looks like so - var_dump($dsq) displays:
    object(SimpleXMLElement)#5 (1) { ["@attributes"]=> array(1) { ["id"]=> string(10) "1191143992" } }

    My guess at how to get the value of 'id' is
    $id = (string) $dsq->@attributes[0]->id;

    This php does not like - how can I get it?

    G

  • #2
    New Coder
    Join Date
    Apr 2014
    Posts
    17
    Thanks
    0
    Thanked 1 Time in 1 Post
    Try the following:

    $id = $dsq['id'];

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fehnris View Post
    Try the following:

    $id = $dsq['id'];
    Thank you, Fehnris. However, that displays as empty. I have also tried the below without success:
    $id = (string)$dsq->attributes()->{'id'};
    $id = (string)$dsq[0]->attributes[0]->id;

  • #4
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,444
    Thanks
    11
    Thanked 310 Times in 309 Posts
    Have you tried $id = $dsq[@id];

    Do you have a snippet of the xml, it may be easier to tell from that.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •