Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8897581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:22:52+00:00 2026-06-15T00:22:52+00:00

I’m using DOMDocument to retrieve several bits of text from a webpage and place

  • 0

I’m using DOMDocument to retrieve several bits of text from a webpage and place them into an array. The same code works on another server, yet doesn’t on mine. I get Trying to get property of non-object for each iteration of the while loop and the array remains empty at the end.

$html = file_get_contents("http://sugarkettle.site44.com/catering.html");
$doc = new DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML($html);
libxml_clear_errors();

$meatPrices = array();

function fillArrayFromDOM($array,$type) {
    global $doc;
    $i = 0;
    $label = 1;
    $array = array();
    while ($label <= 15):
      $array[$i] = $doc->getElementById($type.$label)->textContent;
      $i++;
      $label++;
    endwhile;
    return $array;
}

fillArrayFromDOM($meatPrices,"meat");
echo var_dump($meatPrices); 

Here’s a link to it working:
http://www.evintr.com/willtest.php

He’s running a GoDaddy server and I have a local WAMP (2.2) server. Any configuration options I can provide that might explain why this is happening? Or does the problem have nothing to do with my server config?

Any help much appreciated. Thanks in advance!

Update 1 – 11/16/12

On my server, I’ve tested $meatPrices[1] = $doc->getElementById('meat1')->textContent; and it works. For whatever reason, inside the while loop the same expression (except with variables in the getElementById parameters) tosses an error: Trying to get property of non-object.

Update 2 – 11/17/12

My WAMP server is running PHP version 5.3.13.
My friend’s server is running PHP version 5.3.6.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:22:52+00:00Added an answer on June 15, 2026 at 12:22 am

    Try with adding allow_url_fopen=on in your PHP configuration file (php.ini). Save it and restart Apache; it should work…

    EDIT:
    Check also if you have extension php_openssl.dll enabled (extension=php_openssl.dll in your php.ini file). Again, restart of Apache would be required.

    EDIT:

    It depends on PHP version you have but here are two potential solutions:

    1. replace line fillArrayFromDOM($meatPrices,"meat"); with
      $meatPrices = fillArrayFromDOM($meatPrices,"meat"); You can also
      change your function to remove necessary $meatPrices parameter).

    or

    1. replace line function fillArrayFromDOM($array,$type) { with function fillArrayFromDOM(&$array,$type) { //note new character &; it will keep reference to $array variable so it could be changeable; you can also remove line: $array = array();

    Both should work; I am in rush have no time to wait on your comment response. Let us know what you get…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using domdocument() to retrieve data from a web page, and I want to
I'm using this code to get the alt attribute from img tags using domdocument.
I have my XML feed being created from an associative array. Using new DOMDocument('1.0','UTF-8');
When I try to write UTF-8 Strings into an XML file using DOMDocument it
i'm trying to insert data into xml using php domdocument. however when i hit
i'm inserting the data into an xml file using php domdocument. however when i
I'm importing some arbitrary HTML into a DOMDocument using the loadHTML() function, eg.: $html
im using dom document getElementsByTagName to retrieve a website title. here is my code:
I am using xpath to retrieve the text value of some links (a) in
Given the following PHP code using DOMDocument : $inputs = $xpath->query('//input | //select |

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.