What i need this to do is delete what is inside the div eliment already before it writes the the div again. If anyone can help me i give my thanks, :)

<?php

$file = "./test.html";
$imgs = glob("1/*.*");


$dom = new DOMDocument();
$dom->loadHTMLFile($file);
$container = $dom->getElementByID("container");
if(count($imgs) == 0 || $imgs === false)
    die('Error: glob is failing.');

foreach($imgs as $img)
{
    $basename = pathinfo($img, PATHINFO_BASENAME);
    $tag = $dom->createElement("img");
    $tag->setAttribute('src', '1/'.$basename);
    $container->appendChild($tag);

    $tag = null;
}

$dom->saveHTMLFile($file);

?>

What i need this to do is delete what is inside the div eliment already before it writes the the div again.

What is the before and after situation?

the code will rewrite the file names every time the page loads causing repeated file names. If i use php to delete what is inside the div then the code above will write the file names and they will only be on the line once. as it is when the code above runs everytime you refresh it builds the same thing over and over