How to make an xpath result into a string with PHP?

Discussion in 'PHP' started by babyboy808, Oct 3, 2009.

  1. #1
    if($xmlobj = simplexml_load_string(file_get_contents($xml_feed)))
    {
        $result = $xmlobj->xpath("TrafficMeta");
    }
    PHP:
    The above code returns the desired result and when viewed with print_r it shows this, which is what I want to get (sessionId):
    Array ( [0] => SimpleXMLElement Object ( [sessionId] => tbfm1t45xplzrongbtbdyfa5 ) )
    PHP:
    How can I make this sessionId into a string?
     
    babyboy808, Oct 3, 2009 IP
  2. caprichoso

    caprichoso Well-Known Member

    Messages:
    433
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    110
    #2
    Try
    $id = $result['sessionId'];
    PHP:
    If it doesn't work print the output of this var_dump here.
    var_dump($result);
    PHP:
     
    caprichoso, Oct 3, 2009 IP
  3. renownedmedia

    renownedmedia Well-Known Member

    Messages:
    65
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    100
    #3
    You might need to do something like this:

    $id = $result->sessionId;

    Since this is an object not an array.
     
    renownedmedia, Oct 3, 2009 IP