Explanation of the problem: It's probably skipping every other element because once you remove an iframe, for example, the object (the list of elements) changes in a way that all other iframes shift to ocuppy the removed's spot.

One way to fix it:

// code
$iframes = $dom->getElementsByTagName('iframe');
while($iframes->length > 0){ // while there are still frames left to change
foreach($iframes as $iframe) {
// your regular code to replace iframe with span
// break; // this makes it easier to understand, but not really necessary
}
$iframes = $dom->getElementsByTagName('iframe'); // get the (remaining) skipped frames until there is none left
}
// code