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;
I keep on getting a blank return value when I try to echo various aspect of the dom parts.- when DEBUGGING, use var_dump(), not echo(), to avoid this issue. also make sure that php.ini haserror_reporting=E_ALLanddisplay_error=on(or alternatively, make sure the error log works, and read the error log after running your code)Try to click on the link, you'll see what I mean.what do you mean the link ? your test XML page has 80 different links! which of the 80 links do you mean?I am wanting to print the content between the tags.which tags are you talking about, it has 3679 tags, do you want the content between all of them?