Jump to content

This non-object issue is driving me crazy.


rockman

Recommended Posts

I've got some code that displays a feed from a wordpress xml and it does perfectly on my mamp localhost but when I put it on the windows server everthing just falls apart.

<?php


$curl = curl_init();


curl_setopt_array($curl, Array(
CURLOPT_URL => 'http://blog.thisisfusion.com/feed/',
CURLOPT_USERAGENT => 'spider',
CURLOPT_TIMEOUT => 120,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_ENCODING => 'UTF-8'
));


$data = curl_exec($curl);


curl_close($curl);


$xml = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA);
  
?>

And the loop portion here:

 

 <?php 
$i = 0;
foreach ($xml->channel->item as $item) {
$creator = $item->children('dc', TRUE);
echo '<h2>' . $item->title . '</h2>';
echo '<small>Posted on '. date('l F d, Y', strtotime($item->pubDate)) .' by '.$creator.'</small>
</p>';
echo '<p class="description">' . $item->description . '</p>';
if (++$i > 2) break;
}
?>

It's having a fit on the server saying that THIS section

foreach ($xml->channel->item as $item)

is trying to get the property of a nonobject and that it's an invalid argument in foreach. If this was truly the case, why is it working on my localhost? I've tried a lot of different methods and I have no clue what to do anymore. I var_dumped and didn't see anything maybe something in $xml is null and I missed it? But I checked to make sure that wasn't the case. I don't know. I would appreciate some help. Thank you.

 

 

simplexml_load_string() will return false on failure but also issue warnings along the way. Make sure your php.ini has

error_reporting = -1
display_errors = on
(restart if you have to change it) and try your script again.

 

While you're at it,

var_dump($data);
var_dump($xml);
too.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.