I am trying to get specific value from an external URL. Somehow I'm stuck now. Please somebody see and help.
I am trying to do this with new DOMDocument();
<?php
$html = file_get_contents('https://someurl.com');
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$elements = $xpath->query("//div[@id='post']");
$maindata = $elements[1];
echo $maindata->nodeValue;
?>
Now see the structure of HTML file on target URL
<div id="post" align="left">
<ul>
<li>
<a>some content</a>
</li>
</ul>
</div>
<div id="post" align="left">
<ul>
<li>
<a>some content</a>
</li>
<li>
<a>Targeted Content</a>
</li>
</ul>
</div>
<div id="post" align="left">
<ul>
<li>
<a>some content</a>
</li>
</ul>
</div>
When I tried to get this from an array, it gave me the entire div value (some content Targeted content). I need only targeted content.