2

I have this code:

 <li datetime="2019-06-03T14:45" offset="-135" type="standard"></li>
... etc.

How I can get datetime attribute value if all elements contain attribute type with value standard? So how I can get datetime value (2019-06-03T14:45) from each li element

I tried:

$timeslots = [];
$dom = new \DOMDocument();
@$dom->loadHTML($html);
$xpath = new \DOMXPath($dom);
$entries = $xpath->query('//li[@type="standard"])/@datetime');

foreach($entries as $e) {
  $timeslots[] = $e->textContent;
}

$ts = $timeslots;
return $ts;

but I got an error:

DOMXPath::query(): Invalid expression

2
  • 3
    Think it's the extra ) in li[@type="standard"])/ Commented Jun 2, 2019 at 20:13
  • thanks, thats correct answer Commented Jun 2, 2019 at 20:15

1 Answer 1

2

Thought the issue is resolved, I just want to provide the idea how you can quickly check your xpath here.

This will give you the message if xpath is not correct and you can get idea what's wrong.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.