I'm currently working on a website that requires me to load the image source of an tag from an external website via jQuery or PHP in order to embed that image on my page, is there any way to do this maybe by XPath?
EDIT: Based on additional research I did - both before asking the question here and after - I have now found the solution. Sergey Ligus has given me the right approach. The problem why file_get_contents didn't work was that the page seemed to block this kind of requests and I had to fake a user_agent via stream_context_create.
Example:
$context = stream_context_create([
'http' => [
'user_agent' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)',
],
]);
$html = file_get_contents('URL', false, $context);
$dom = new DOMDocument();
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$result = '';
foreach ($xpath->query('XPATH') as $child) {
$result .= $dom->saveHTML($child);
}