<?php
$html = '<!doctype html>
<html>
<head>
<title>test</title>
</head>
<body>
<a id="1">
<b>value1</b>
<b>value2</b>
</a>
<a id="2">
<b>value1</b>
</a>
</body>
</html>';
$doc = new DOMDocument();
$doc->loadHTML($html);
$xpath = new DOMXpath($doc);
$nodes = $xpath->query("//b[contains(., 'value1')] | //b[contains(., 'value2')]");
$parent_id = $nodes->item(0)->parentNode->getAttribute("id");
echo $parent_id;
- Output for 5.5.0 - 5.5.37, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
- 1
preferences:
122.94 ms | 404 KiB | 221 Q