Skip to main content

Remove Image Tags from HTML using PHP

With websites such as a forums, users post all kinds of images which creates headache to administrator. But you can easily remove images tfrom a html content using PHP preg_replace and some customized regular expression code. Here is the complete code to remove image tags from a html string.

<?php
$html_content = 'This is a image remove example with php';
$html_content = preg_replace('/(<)([img])(\w+)([^>]*>)/','', $html_content);
echo $html_content;

Leave a Reply

Your email address will not be published. Required fields are marked *

Shares

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!