Parsing <contend:encoded> attribute from a wordpress feed with simplexml

wordpressThat was a long title for this post o_o. Well , I first must clarify that my blog is not a wordpress mod, however it doesn’t mean I don’t have to work with wordpress at some point in the day. Recently I was doing a newsletter for a Website and I decided I would parse the RSS from that website to get the 4 newest contents however I ran into a trouble while using PHP’s SimpleXML class and this was that I SimpleXML couldn’t parse the contentn since it came with what is called namespace. For those of you who only came in here for the solution here it is =)

Replace <content:encoded> for <content> 😉

this is a simple example on how I did it

 

	$data = file_get_contents(“http://myurls.com/feed.xml”);
	$data = str_replace("content:encoded>","content>",$data);
	$xml = simplexml_load_string($data);
	$item = $xml->channel;
	
	foreach($item->item AS $art)
	{
		$content = $art->content;    
		echo $content;
	}

and thats it.

For those of you who kept reading I’m gonna tell you the solution to this problem, it’s indeed quite easy. Indeed a namespace tell us that what’s inside that tag is encoded in some other weird standard but don’t worry, the same feed it’s telling you what it is. if you see at the begining of the wordpress feed you’ll see this:
 

			

2 thoughts on “Parsing <contend:encoded> attribute from a wordpress feed with simplexml

  1. First, you should pick the bodily to be used while creating the rule bags with logo. It has to be durable continuance|lasting}|abiding|continuing|stable|durable}, affordable and allowing you several options. The bodily should not frontier you on the way you can customize the bag and should also warrant you drawn out term use. Another {grave|bodily|of importance|of moment|of great weight|important} agent about the bodily used is that it should hold the right appeal to the recipients of the lead bags. This demands that you prove to be identical your target clients and know what appeals to them and use that. However, if it is a general|of the whole|not partial|not special|not particular|general} marketing campaign, go for all-reaching bodily such as cotton and canvas.

  2. In the past few years, services like Facebook and Twitter have
    become very popular ways for people to share the content they read on the
    web. These types of services are much in demand in the current order online,
    especially to webmasters and owners of e-commerce.
    Around the net every thing can look being nonetheless, as
    opposed to in television in which it’s all about motion.

Leave a Reply

Your email address will not be published. Required fields are marked *