0

i have a small issue regarding extracting td value by th value

here is a table example:

<table>
<tr><th>Name:</th><td>Will</td></tr>
<tr><th>Size:</th><td>41</td></tr>
<tr><th>Clock:</th><td>GMT</td></tr>
</table>

i Would like to get The "Will" value By Th value "Name:"

in Jquery i do :

$('th:contains(Name:)').next().text(); //Will Show Will
$('th:contains(Size:)').next().text(); //Will show 41

However would like to do it via PHP DOMDocument

$dom = new DOMDocument();
$html = $dom->loadHTMLFile("src/load.html");
$dom->preserveWhiteSpace = false; 
$selector = new DOMXPath($dom);

$name=$selector->query('//th[contains(.,"Name:")]')->?
$size=$selector->query('//th[contains(.,"Size:")]')->?

Thank you

1 Answer 1

1
//th[contains(.,"Name:")]/following-sibling::td[1]
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.