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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:11:26+00:00 2026-06-03T05:11:26+00:00

I have a page that looks something like this: … <div class=container> <div class=info>

  • 0

I have a page that looks something like this:

...
<div class="container">

<div class="info">
<h3>Info 1</h3>
<span class="title">Title for Info 1</span>
<a href="http://www.example.com/1">Link to Example 1</a>
</div> <!-- /info -->

<div class="info">
<h3>Info 2</h3>
<span class="title">Title for Info 2</span>
<a href="http://www.example.com/2">Link to Example 2</a>
</div> <!-- /info -->

<div class="info">
<h3>Info 3</h3>
<span class="title">Title for Info 3</span>
<a href="http://www.example.com/3">Link to Example 3</a>
</div> <!-- /info -->

</div> <!-- /container -->
...

The structure of each of the info class divs is the same, and I’d like to be able to loop through the document and for each div with a class of info, parse the various component into either an array or individual variables for the purposes of outputting the data in some sort of human-readable format, like a csv file or HTML table.

I’ve tried using the DOMDocument method, and using getElementByTagName to extract the contents of each tag, but because the div contains multiple tag types (h3, a, span), I haven’t figure out how to accomplish what I’m looking to do.

In the end, I want to be able to put the data in a format like this:

divclass, h3, spanclass, spantitle, ahref, a
info, Info 1, title, Title for Info 1, http://www.example.com/1, Link to Example 1
...

Thanks!

  • 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-03T05:11:27+00:00Added an answer on June 3, 2026 at 5:11 am
    <?php
    $html = '
    <div class="container">
    
    <div class="info">
    <h3>Info 1</h3>
    <span class="title">Title for Info 1</span>
    <a href="http://www.example.com/1">Link to Example 1</a>
    </div> <!-- /info -->
    
    <div class="info">
    <h3>Info 2</h3>
    <span class="title">Title for Info 2</span>
    <a href="http://www.example.com/2">Link to Example 2</a>
    </div> <!-- /info -->
    
    <div class="info">
    <h3>Info 3</h3>
    <span class="title">Title for Info 3</span>
    <a href="http://www.example.com/3">Link to Example 3</a>
    </div> <!-- /info -->
    
    </div> <!-- /container -->
    ';
    
    
    $dom_document = new DOMDocument();
    
    $dom_document->loadHTML($html);
    $dom_document->preserveWhiteSpace = false;
    
    //use DOMXpath to navigate the html with the DOM
    $dom_xpath = new DOMXpath($dom_document);
    
    $elements = $dom_xpath->query("//*[@class='info']");
    
    if (!is_null($elements)) {
    
      foreach ($elements as $element) {
        echo "\n[". $element->nodeName. "]";
    
        $nodes = $element->childNodes;
        foreach ($nodes as $node) {
          echo $node->nodeValue. "\n";
        }
    
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that looks like this: <div class=post> <h1>Foo Bar</h1> </div> I
I have an tag on my page that looks something like this: <a href=javascript:void();
I have an input field on a page that looks something like this: <input
I have a aspx page that looks something like this: <tr id=Row1> <td>Some label</td>
I have a aspx page that looks something like this: <table runat=server id=tblTEst> <tr
I have Servlet that looks something like this: public class MyServlet extends Servlet {
I have code that looks something like this: <html> <head> <script type=text/javascript src=http://code.jquery.com/jquery-latest.min.js></script> <script
i have an xml file that looks something like this <library> <book name=ABC> <chapter
I have a Query that looks something like this (I know its vulnerable to
I have code, that looks something like this: (function($) { $(document).ready(function() { function getHash(){

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.