Jump to content

This non-object issue is driving me crazy.


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.


$curl = curl_init();

curl_setopt_array($curl, Array(
CURLOPT_URL => 'http://blog.thisisfusion.com/feed/',

$data = curl_exec($curl);


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

And the loop portion here:


$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>
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.



Link to comment
Share on other sites

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,

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.