SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru risoknop's Avatar
    Join Date
    Feb 2008
    Location
    end($world)
    Posts
    834
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to convert SimpleXMLElement attribute to string

    I have a SimpleXMLElement and what I want to do is use one of its attributes as an array index:

    PHP Code:

    $element 
    $xml->path->to->element;

    $array = array();
    $attribute $element['attribute'];
    $array[$attribute] = 'yadayada'
    I get 'Illegal offset type' error. Is it somehow possible to convert the element attribute to string?

    Thank you.

  2. #2
    SitePoint Addict
    Join Date
    Oct 2008
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure if this will help you but you can typecast
    PHP Code:
    $var = (string) $var
    http://www.php.net/manual/en/languag...string.casting

  3. #3
    SitePoint Guru risoknop's Avatar
    Join Date
    Feb 2008
    Location
    end($world)
    Posts
    834
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks that worked, I forgot typecasting works in PHP.


Bookmarks

Posting Permissions

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