I don't have experience in regex. I am just trying to find a way to detect and delete every character outside of the img tag. In other words I want to strip a given html code from all text and tags and just keep everything within the img tags. The result should show just the image tags like that:
<img src="sourcehere">
Is there a way to do this?
UPDATE: I need specifically a regex that goes in preg_replace. This is what I have done, but it doesn't work:
$buffer ="<html><head></head><body><img src='image.jpg'></body></html>";
$buffer = preg_replace('(?i)<(?!img|/img).*?>', '', $buffer);
echo $buffer; /* should output <img src='image.jpg'> but it doesn't */