themazz
themazz

Reputation: 1147

Remove linked images from string

I need some help with a new function which I am developing. The problem is that I don't know how to solve it.

I have an string with HTML code inside and what I want to do is to remove all the images inside which are with a link:

$string = "html code html code **<a href=""><img src="" /></a>**";

I have been thinking in the use of preg_replace(); but I don't know how could it be the pattern.

Upvotes: 0

Views: 812

Answers (1)

Zathrus Writer
Zathrus Writer

Reputation: 4331

Try:

$result = preg_replace('/<a href="[^"]*">[^<]*<img src="[^"]*"[^>]*>[^<]*<\/a>/sim', '', $subject);

Upvotes: 2

Related Questions