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'm using the following in the web page but can't get a response from
I am trying to get the text from a page scrape using xpath, now
I wanna get the Timedate value from another page using request.querystring and then use
In HTML, you can send data from one page to another using a GET
I want to get user input in one page, store that in a php
I finally succeeded in using Ajax to get SOMETHING sent from one page to
I'm trying to retrieve an webpage that has XML data using file_get_contents(). $get_url_report =
How to get ViewData in loaded page, using Asp.net MVC and javascript ?
I'm attempting to get my first ASP.NET web page working on windows using Mono
I have forms in my page a get and a post and i want

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.