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

  • SEARCH
  • Home
  • 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 7403157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:58:59+00:00 2026-05-29T04:58:59+00:00

I am trying to extract some info from a website using simple_html_dom. Currently I

  • 0

I am trying to extract some info from a website using simple_html_dom.

Currently I am using:

foreach ($html->find('div.product') as $results) {
    foreach ($results->find('div.image') as $img) {
        echo $img;
    }
    foreach ($results->find('a.title') as $title) {
        echo $title->plaintext;
    }
    foreach ($results->find('div.price') as $price) {
        echo $price;
    }
}

Which works fine. However I need to be able to echo each variable outside of the foreach loop. If I do that using the above code, only the final result will be displayed, i.e. out of the 10 products I am trying to extract only the 10th will be displayed.

Is there a way I can use an array to store all the results from each foreach loop then echo them out once the overall loop is finished?

Something like this:

foreach ($html->find('div.product') as $results) {
    foreach ($results->find('div.image') as $img) {
        array($img);
    }
    foreach ($results->find('a.title') as $title) {
        array($title->plaintext);
    }
    foreach ($results->find('div.price') as $price) {
        array($price);
    }
}
echo array($img);
echo array($title);
echo array($price);

Sorry if this question is confusing I don’t have the best grasp on PHP, especially arrays!

  • 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-05-29T04:59:00+00:00Added an answer on May 29, 2026 at 4:59 am
    $array_img = array();
    $array_title = array();
    $array_price = array();
    foreach ($html->find('div.product') as $results) {
        foreach ($results->find('div.image') as $img) {
            $array_img[] = $img;
        }
        foreach ($results->find('a.title') as $title) {
            $array_title[]= $title->plaintext;
        }
        foreach ($results->find('div.price') as $price) {
            $array_price[]= $price;
        }
    }
    echo '<pre>';
    print_r($array_img);
    print_r($array_title);
    print_r($array_price);
    echo '</pre>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use WWW::Mechanize to extract some links from the HTML page using
I am trying to extract some data from a website using a LINQ statement,
I'm trying to extract some data from various HTML pages using a python program.
I'm trying to extract some information from a webpage using php cURL+preg_match or any
I am trying to extract the title from this xml: <entry> ... <title type=html>Some
I'm trying to extract some extra information from a location using google map api.
I'm trying to write a code to extract some form data from a HTML
I'm trying to extract some DNA info from a file. Before the DNA data
I'm trying to extract some string from a file using python re, then MD5ing
Hi Everybody, I'm Currently using preg_match and I'm trying to extract some informations enclosed

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.