I'm trying to parse an RSS feed and I am getting what appears to be an empty DOM Document object. My current code is:
$xml_url = "https://thehockeywriters.com/category/san-jose-sharks/feed/";
$curl = curl_init();
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $curl, CURLOPT_URL, $xml_url );
$xml = curl_exec( $curl );
curl_close( $curl );
//$xml = iconv('UTF-8', 'UTF-8//IGNORE', $xml);
//$xml = utf8_encode($xml);
$document = new DOMDocument;
$document->loadXML( $xml );
if( ini_get('allow_url_fopen') ) {
echo "allow url fopen? Yes";
}
echo "<br />";
var_dump($document);
$items = $document->getElementsByTagName("item");
foreach ($items as $item) {
$title = $item->getElementsByTagName('title');
echo $title;
}
$url = 'https://thehockeywriters.com/category/san-jose-sharks/feed/';
$xml = simplexml_load_file($url);
foreach ($items as $item) {
$title = $item->title;
echo $title;
}
print_r($xml);
echo "<br />";
var_dump($xml);
echo "<br />hello?";
This code is two separate attempts at parsing the same url based on answers and suggestions given in the following examples found on stack overflow:
Example 1
Example 2
Things I have tried or looked up:
1. Checked to make sure that allow_url_fopen
is allowed
2. Made sure that there is UTF encoding
3. Validated the XML
4. Code examples provided on previously linked Stack Overflow posts
Here is my current output with the var_dumps
and echo's
allow url fopen? Yes
object(DOMDocument)#2 (34) { ["doctype"]=> NULL ["implementation"]=> string(22) "(object value omitted)"
["documentElement"]=> NULL ["actualEncoding"]=> NULL ["encoding"]=> NULL
["xmlEncoding"]=> NULL ["standalone"]=> bool(true) ["xmlStandalone"]=> bool(true)
["version"]=> string(3) "1.0" ["xmlVersion"]=> string(3) "1.0"
["strictErrorChecking"]=> bool(true) ["documentURI"]=> NULL ["config"]=> NULL
["formatOutput"]=> bool(false) ["validateOnParse"]=> bool(false) ["resolveExternals"]=> bool(false)
["preserveWhiteSpace"]=> bool(true) ["recover"]=> bool(false) ["substituteEntities"]=> bool(false)
["nodeName"]=> string(9) "#document" ["nodeValue"]=> NULL ["nodeType"]=> int(9) ["parentNode"]=> NULL
["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL
["previousSibling"]=> NULL ["attributes"]=> NULL ["ownerDocument"]=> NULL ["namespaceURI"]=> NULL
["prefix"]=> string(0) "" ["localName"]=> NULL ["baseURI"]=> NULL ["textContent"]=> string(0) "" }
bool(false)
hello?