0 users online. Create an account or sign in to join them.Users


Messing with the twitter extension to grab first media image that's in a tweet. It's working but how do I make the XML slightly neater?

    foreach ($this->_tweet_values as $key) {
    if (array_key_exists($key, $tweet)) {

        if($key != 'entities'){

            $t->appendChild(new XMLElement($key, __(General::sanitize($tweet[$key]))));

        } else {

            foreach ($tweet[entities] as $key => $entities) {                                   
                if($key != 'media'){

                    $t->appendChild(new XMLElement($key, $tweet[entities][$key]));

                } else {

                    foreach ($tweet[entities][media][0] as $key => $media) {                            
                            $t->appendChild(new XMLElement($key, $tweet[entities][media][0][$key]));




Puts the nodes of the media entities on the same level as the tweet nodes, how could I tell XMLElement that I want to have them as a child node of say "media", for example


My first guess resulted in a separate


per item because I'm inside the foreach.

Give us a clue?

Can I see a little more context? You have variables defined out of the scope of your foreach, can I see them too?

Hi, sorry it's just the data.base.php from this Twitter extension


It's around line 184 where I was just trying to add a little recursion to get at the entities part of tweets that I think got added to Twitter since this extension was made. I think you'd perhaps use RecursiveArrayIterator instead but that'd be different to how this original code has done it.

I'm getting confused I think with XMLElement and didn't get how to put nodes inside other nodes in the output XML. Or rather several nodes into a parent one, as I did manage to create several same nodes with a different child in each.

Probably I'm thinking about it the wrong way round. I'm on the live server too because of the OAUTH callback URL so can't see what's going on in the background, just the output XML in ?debug.

Cheers designermonkey

There is an example of the JSON structure here


I've just been drilling straight down to the media_url_https as that's what I needed but there's other nice stuff in there for people with other kinds of tweet.

Working now, I split the stuff up into separate arrays and it worked so I must have had things in the wrong order earlier.

Dude, sorry I didn't get back to you. Had a hectic weekend.

Glad you got it sorted out though.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details