1

It's really quite simple. I'd like to $item->addChild('media:thumbnail') but it's not behaving as it removes 'media:'...

I am wondering how the following can be accomplished using SimpleXMLElement.

$thumbnail=$item->addChild('media:thumbnail');
$thumbnail->addAttribute('url', $row['url']);
$thumbnail->addAttribute('height', '81');
$thumbnail->addAttribute('width', '144');
//Output <media:thumbnail url="http://myurl.com/my.jpg" width="144" height="81" />
hakre
  • 193,403
  • 52
  • 435
  • 836
user1645914
  • 371
  • 6
  • 23
  • Your linked document indicates that `$namespace` should come as third parameter, instead of combined into the first one... – Passerby Jan 10 '13 at 03:21

1 Answers1

1

Correct Answer:

    $thumbnail=('media:thumbnail', '', 'http://search.yahoo.com/mrss/');
    $thumbnail->addAttribute('url', $row['url']);
    $thumbnail->addAttribute('height', '81');
    $thumbnail->addAttribute('width', '144');
    //Output <media:thumbnail url="http://myurl.com/my.jpg" width="144" height="81" />
user1645914
  • 371
  • 6
  • 23
  • and if i want to insert a child to 'media:thumbnail' node? – Nikitas Feb 13 '14 at 12:37
  • 1
    @user1545914 You forgot `$thumbnail = $item->addChild(...)` @Nikitas You just use `$thumbnail->addChild('tag', 'value')` or `$thumbnail->addChild('namespace:tag', 'value', 'http://ns1.example.com/ns/')` – Lars Gyrup Brink Nielsen May 22 '14 at 20:47