<?php $html = '<a href="#"><img src="image1"></a>blabla<a href="#">Without an image</a><a href="#"><img src="image2"></a>'; $domDocument = new \DOMDocument(); $domDocument->loadHTML($html); $xpath = new DOMXPath($domDocument); foreach ($xpath->query('//a[./img]') as $imageLink) { echo $domDocument->saveHTML($imageLink), PHP_EOL; }
You have javascript disabled. You will not be able to edit any code.