简体   繁体   中英

SimpleXml and php: how to add an enclosure into an RSS?

I read the XML file and loop throught the links to get link to pdf linked.

Then I want to add this link as value for the element tag of RSS. This rag must be added

$XML = simplexml_load_file($cached_rss);
foreach ($XML->channel->item as $index => $item) 
{ 
    // I read the page linked, grab a link to a pdf 
    // Then tried to add the new TAG to current item
    $XML->channel->item[$index]->addChild("enclosure", $link);
}

Actually this causes php crash without errors (any errors even in apache error.log files!)

What must I do to add a new tag as child of an existen 'item' tag?

You're already getting the $item in your foreach - that's where you want to addChild : $item->addChild("enclosure", $link);

I'm not sure why you didn't get errors tho. Try to make sure your error_reporting is set to E_ALL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM