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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:13:47+00:00 2026-05-28T11:13:47+00:00

I would like to parse the following id: date How would I select it?

  • 0

I would like to parse the following id: date

How would I select it? I know how to select a class but I have had no luck for an id.

This is what I did with classes:

$xml->xpath('//*[@class="date"]'); 

I tried switching @class for @id but no luck. What am I doing wrong?

Thank you in advance

@$doc=new DOMDocument();
@$doc->loadHTML($html5);

$xml=simplexml_import_dom($doc);
$images=$xml->xpath('//*[@id="date"]'); 
$arr= array();
foreach ($images as $img) {
  $arr[]= $img;
}

echo $arr[0];
  • 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-28T11:13:48+00:00Added an answer on May 28, 2026 at 11:13 am

    Now that you made me feel bad …

    The xpath query below will retrieve all elements that have the attribute id = date. Since you only care about the first one (there shouldn’t be more than one because ID attributes are supposed to be unique … but you never know), you need to reference item(0) in the DOMNodeList returned by the xpath query.

    $xml = '<root><p>element we don\'t care about</p><p id="date">date element text</p></root>';
    $doc = new DomDocument;
    $doc->loadXML($xml);
    
    $xpath = new DOMXPath($doc);
    if ($el = $xpath->query("//*[@id='date']")->item(0)) {
      echo $el->nodeValue; // outputs: date element text
    } else {
      echo 'no elements exist in the xml with an "id" attribute';
    }
    

    Hope that helps.

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

Sidebar

Related Questions

I have following code: string date = 13.04.2012; string date2 = (DateTime.Parse(date).AddDays(1)).ToString(); This is
I have the following XML document which I would like to parse into a
I've got the following below XML and would like to parse this with JQuery
I would like to know the procedure to adopt to parse and obtain text
I would like to know if there is a simple way to parse HTML
I would like to know if ParseExact is faster than Parse. I think that
I have a date range that I would like to be able to loop
I would like to parse following string to get the value 46.4400 INR <div
I have following method that I would like to make shorter or faster if
I have string looking like this: 01 02 03 99 I'd like to parse

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.