Hoping I can get some help with this, PHP is not my strong point, still learning the ropes...
So I have a php form that creates an RSS file, the RSS feed will be used on an internal intranet by helpdesk staff to keep up to date with current issues that arise in the network.
The form is intended to be used as a front end for managing the feed and the last thing I need to do is be able to delete a specific item from the feed.
I want to delete item's with specific GUID's, when the form creates the item the GUID is simply given a value using time(), I'm stuck at how I even find the item I want to delete, I guess I need to search the items to match the guid element then delete the child it appears in... can someone give me some helpful pointers?
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<item>
<title>Exchange Server being rebooted</title>
<description>Exchange servers are currently being rebooted</description>
<author>Self</author>
<link></link>
<pubDate>Fri, 26 Aug 2011 08:37:12</pub开发者_运维技巧Date>
<guid>1314311832</guid>
</item>
</channel>
</rss>
When I display the items from the RSS in the form I'll be putting a link with the GUID that when clicked should delete that item.
Hope this makes sense.
Thanks,
You may use DOMXPath to retrieve the GUID-elements and removeChild() to remove them:
$xpath = new DOMXPath($yourDOMDocument);
$query = '//rss/channel/item/guid[boolean(.="1314311832")]';
$entries = $xpath->query($query);
foreach ($entries as $entry) {
$entry->parentNode->parentNode->removeChild($entry->parentNode);
}
精彩评论