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 722019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:56:25+00:00 2026-05-14T05:56:25+00:00

I get a page using file_get_contents from a remote server, but I want to

  • 0

I get a page using file_get_contents from a remote server, but I want to filter that page and get a DIV from it that has class “text” using PHP. I started with DOMDocument but I’m lost now.

Any help?

$file = file_get_contents("xx");
$elements = new DOMDocument();
$elements->loadHTML($file);
foreach ($elements as $element) {
    if( !is_null($element->attributes)) {
        foreach ($element->attributes as $attrName => $attrNode) {
            if( $attrName == "class" && $attrNode== "text") {
                echo $element;
            }
        }
    }
}
  • 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-14T05:56:25+00:00Added an answer on May 14, 2026 at 5:56 am

    Once you have loaded the document to a DOMDocument instance, you can use XPath queries on it — which might be easier than going yourself through the DOM.

    For that, you can use the DOMXpath class.

    For example, you should be able to do something like this :

    $dom = new DOMDocument();
    $dom->loadHTML($html);
    
    $xpath = new DOMXPath($dom);
    $tags = $xpath->query('//div[@class="text"]');
    foreach ($tags as $tag) {
        var_dump($tag->textContent);
    }
    

    (Not tested, so you might need to adapt the XPath query a bit…)

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

Sidebar

Related Questions

I am trying to get the text from a page scrape using xpath, now
i have this simple code to load data from other php page using get
I'm using the following code to get response from a requested page using php
Could someone recommend a way to get page name from a url using JavaScript?
Is it possible for a web page using Javascript to get data from another
Is it possible to get all div's within a page using jQuery including nested
I want to copy a file from a remote server to a local server
I'm trying to retrieve an webpage that has XML data using file_get_contents(). $get_url_report =
I'm using Drupal 7. My bg image in page.tpl.php file and image get to
How to get previous page URL using jQuery? I am using the following code

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.