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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:40:31+00:00 2026-06-08T19:40:31+00:00

Using PHP and DOM how do I get the PLACE, ADDRESS, LOCALITY, REGION, POSTAL

  • 0

Using PHP and DOM how do I get the PLACE, ADDRESS, LOCALITY, REGION, POSTAL CODE and COUNTRY from the following code ( part of a web page ).

Since now I have developed a part of the code to get other content. This is the code so far.

$dochtml = new DOMDocument();
$dochtml->loadHTMLfile('');
$xpath = new DOMXpath($dochtml);

$descr = $xpath->query('//div[@class="description"]')->item(0);
    print_r($descr->nodeValue);

$abbr  = $dochtml->getElementsByTagName("abbr")->item(0);
    $title = $abbr->getAttribute("title");
    echo $title;

This is the rest of the code.

<div class="vcard location p">
    <div class="fn org">
        <a href="link here">PLACE</a>
    </div>
    <div class="adr">
        <div class="street-address">ADDRESS<br></div>
        <div>
            <span class="locality">LOCALITY</span>,
            <span class="region">REGION</span>
            <span class="postal-code">POSTAL CODE</span>,
            <span class="country-name">COUNTRY</span>
        </div>
    </div>
</div>

UPDATE

I have a tiny problem with the following, in the page there are a lot of <abbr> tags however the two tags I want with classes dtstart and dtend as below are the only that are inside the #eventDetailInfo. Unfortunately, not all have the second abbr tag with the class=dtend so it gets the first from the “related events”. So my question is how do I restrict it only to this specific id?

<div id="eventDetailInfo">
        <div class="p">
         <div><abbr class="dtstart" title="2012-07-16T21:00:00">Monday, July 16th, 2012</abbr></div>    
         <div><abbr class="dtend" title="2012-08-16T21:00:00">Monday, August 16th, 2012</abbr></div>    
        </div>
</div>
  • 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-08T19:40:33+00:00Added an answer on June 8, 2026 at 7:40 pm

    From reading the DOMXPath documentation, my suggested solution is outlined below.

    Get elements by class

    $nodes = $xpath->query('//div[contains(@class, "street-address")]');
    

    Get elements by ID

    $node = $xpath->query('//div[@id="someid"]');
    

    Solution

    To extract your values you could use something like (working example):

    <?php
    $html = '<div class="vcard location p">
        <div class="fn org">
            <a href="link here">PLACE</a>
        </div>
        <div class="adr">
            <div class="street-address">ADDRESS<br></div>
            <div>
                <span class="locality">LOCALITY</span>,
                <span class="region">REGION</span>
                <span class="postal-code">POSTAL CODE</span>,
                <span class="country-name">COUNTRY</span>
            </div>
        </div>
        <div id="eventDetailInfo">
            <div class="p">
             <div><abbr class="dtstart" title="2012-07-16T21:00:00">Monday, July 16th, 2012</abbr></div>    
             <div><abbr class="dtend" title="2012-08-16T21:00:00">Monday, August 16th, 2012</abbr></div>    
            </div>
        </div>
    </div>';
    
    $document = new DOMDocument();
    $document->loadHTML($html);
    $xPath = new DOMXpath($document);
    
    function extractNodeValue($query, $xPath, $attribute = null) {
        $node = $xPath->query("//{$query}")->item(0);
        if (!$node) {
            return null;
        }
        return $attribute ? $node->getAttribute($attribute) : $node->nodeValue;
    }
    
    $place = extractNodeValue('div[contains(@class, "fn")]/a', $xPath);
    $address = extractNodeValue('div[contains(@class, "street-address")]',$xPath);
    $locality = extractNodeValue('span[contains(@class, "locality")]',$xPath);
    $region = extractNodeValue('span[contains(@class, "region")]', $xPath);
    $postalCode = extractNodeValue('span[contains(@class, "postal-code")]', $xPath);
    $countryName = extractNodeValue('span[contains(@class, "country-name")]', $xPath);
    $start = extractNodeValue('div[@id="eventDetailInfo"]/div/div/abbr[contains(@class, "dtstart")]', $xPath, 'title');
    $end = extractNodeValue('div[@id="eventDetailInfo"]/div/div/abbr[contains(@class, "dtend")]', $xPath, 'title');
    
    var_dump($place, $address, $locality, $region, $postalCode, $countryName, $start, $end);
    

    Output:

    string(5) "PLACE" string(7) "ADDRESS" string(8) "LOCALITY" string(6) "REGION" string(11) "POSTAL CODE" string(7) "COUNTRY" string(19) "2012-07-16T21:00:00" string(19) "2012-08-16T21:00:00"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently using the PHP DOM to get the BODY tag from HTML.
I'm using PHP Simple HTML DOM Parser with following code snippet: <?php include_once('../simple_html_dom.php'); $html
I'm using simple_html_dom.php to get all images from an url (like pinterest does) if($_POST['submit'])
I'm using PHP/Zend to load html into a DOM, and then I get a
Ho to make this simple xml with php using DOM? Full code will be
After load content to page using div.load('page.php'); I need get all of links from
I am using the following code for parsing dom document but at the end
Possible Duplicate: How to extract a node attribute from XML using PHP's DOM Parser
I'm using PHP DOM and I'm trying to get an element within a DOM
i would like to get the poster image url using php from imdb from

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.