With websites such as a forum, users often get the feeling that they can post all kinds of images which creates headache to administrator. But you can easily remove images from 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.
- $html_content = ‘This is a image remove <img src=”image.png”/> example with <img src=”image.png”/> php…’;
- $html_content = preg_replace(‘/(<)([img])(\w+)([^>]*>)/’, ”, $html_content);
- echo $html_content;