获取远程页面的源代码然后根据其id显示一个div

exactly as its descriped in the title currently my code is:

<?php
    $url = "remotesite.com/page1.html";
    $html = file_get_contents($url);
    $doc = new DOMDocument(); // create DOMDocument
    libxml_use_internal_errors(true);
    $doc->loadHTML($html); // load HTML you can add $html

    $elements = $doc->getElementsByTagName('div');

?>

my coding skills are very basic so at this point i am lost and dont know how to display only the div that has the id id=mydiv

If you have PHP 5.3.6 or higher you can do the following:

$url = "remotesite.com/page1.html";
$html = file_get_contents($url);
$doc = new DOMDocument(); // create DOMDocument
libxml_use_internal_errors(true);
$doc->loadHTML($html); // load HTML you can add $html
$testElement = $doc->getElementById('divIDName');
echo $doc->saveHTML($testElement);

http://php.net/manual/en/domdocument.getelementbyid.php

If you have a lower version I believe you would need to copy the Dom node once you found it with getElementById into a new DomDocument object.

$elementDoc = new DOMDocument();
$cloned = $testElement->cloneNode(TRUE);
$elementDoc->appendChild($elementDoc->importNode($cloned,TRUE));
echo $elementDoc->saveHTML();