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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:26:28+00:00 2026-05-29T05:26:28+00:00

I want to select just a class on its own called .date For some

  • 0

I want to select just a class on its own called .date

For some reason, I cannot get this to work. If anyone knows what is wrong with my code, it would be much appreciated.

@$doc = new DOMDocument();
@$doc->loadHTML($html);
$xml = simplexml_import_dom($doc); // just to make xpath more simple
$images = $xml->xpath('//[@class="date"]');                             
foreach ($images as $img)
{
    echo  $img." ";
}
  • 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-29T05:26:29+00:00Added an answer on May 29, 2026 at 5:26 am

    I want to write the canonical answer to this question because the answer above has a problem.

    Our problem

    The CSS selector:

    .foo
    

    will select any element that has the class foo.

    How do you do this in XPath?

    Although XPath is more powerful than CSS, XPath doesn’t have a native equivalent of a CSS class selector. However, there is a solution.

    The right way to do it

    The equivalent selector in XPath is:

    //*[contains(concat(" ", normalize-space(@class), " "), " foo ")]
    

    The function normalize-space strips leading and trailing whitespace (and also replaces sequences of whitespace characters by a single space).

    (In a more general sense) this is also the equivalent of the CSS selector:

    *[class~="foo"]
    

    which will match any element whose class attribute value is a list of whitespace-separated values, one of which is exactly equal to foo.

    A couple of obvious, but wrong ways to do it

    The XPath selector:

    //*[@class="foo"]
    

    doesn’t work! because it won’t match an element that has more than one class, for example

    <div class="foo bar">
    

    It also won’t match if there is any extra whitespace around the class name:

    <div class="  foo ">
    

    The ‘improved’ XPath selector

    //*[contains(@class, "foo")]
    

    doesn’t work either! because it wrongly matches elements with the class foobar, for example

    <div class="foobar">
    

    Credit goes to this fella, who was the earliest published solution to this problem that I found on the web:
    http://dubinko.info/blog/2007/10/01/simple-parsing-of-space-seprated-attributes-in-xpathxslt/

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

Sidebar

Related Questions

Simple question, I just want to select the text from the <Template> tag. Here's
I want to SELECT a formatted date string from a datetime type in SQL
G'day! I want my WPF ComboBox to display some alternative text when its data-bound
I want to learn jQuery. In my opinion jQuery just select the element you
I want to select number 4 or 5 links i have tried using this
i have users table and i have posts table i want select from users
I want to select the topmost element in a document that has a given
I want to select a bunch of span s in a div whose CSS
I want to select records that are 1 month old or newer. The query
I want to select the top N rows of a table, ranked by how

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.