PHP XML tag contains colon

With PHPs’ simple xml functions it is possible to read xml easily. However, that doesn’t work any longer when a tag contains a colon. That tag is simply ignored and can’t be accessed. Often in RSS feeds there is content:encoded.

There is a trick. Instead of using simplexml_load_file use

$feed = file_get_contents($url);
$feed = str_replace("<content:encoded>", "<contentEncoded>", $feed);
$feed = str_replace("</content:encoded>", "</contentEncoded>", $feed);
$xml = simplexml_load_string($feed);

have fun!

Posts Tagged simplexml

Archives by Month: