So my brother and I decided to parse xml content from a website using CURL and Dom.
I keep on getting a blank return value when I try to echo various aspect of the dom parts.
Here are some details:
- An example website url we are CURLing and using Dom for is like this: https://event.on24.com/eventRegistration/EventServlet?eventid=2062141&sessionid=1&key=FD3181776AA1D3051A0CE6249F1A391A&filter=eventsessionmediapresentationlogplayerxmlformateventrootmediabaseurldialininfomobileenvondemandexcludequestionexcludemessagesexcludeslides
- Notice the URL is not the direct path to an XML file. But on that page it has XML content. Try to click on the link, you'll see what I mean.
- I am wanting to print the content between the tags.
- The way I am using the CURL and Dom scripts are either not right or something else is wrong.
I've tried various echos in different areas of my code but all have returned a blank value. When I try to echo $parsedcontent
it comes up with a blank.
When I try to echo "Hello World" after the "Foreach... 'span' as..." it doesn't print anything.
$urlcontent = $event['url'];
$chcontent = curl_init();
$timeoutcontent = 5;
curl_setopt($chcontent, CURLOPT_URL, $urlcontent);
curl_setopt($chcontent, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($chcontent, CURLOPT_CONNECTTIMEOUT, $timeoutcontent);
curl_setopt($chcontent, CURLOPT_SSL_VERIFYPEER, false);
$htmlcontent = curl_exec($chcontent);
$infocontent = curl_getinfo($chcontent);
curl_close($chcontent);
@$domcontent->loadXML($htmlcontent);
foreach($domcontent->getElementsByTagName('span') as $spanon24content) {
# Get url and title from <a> tags
$innerHTMLspan = '';
$childrenspan = $spanon24content->childNodes;
foreach ($childrenspan as $childspan) {
$innerHTMLspan .= $divspanon24content->ownerDocument->saveXML($childspan);
}
}
$parsedcontent = $innerHTMLspan;
echo $parsedcontent;