-4

I have a long string that contain many img tags (PHP):

$content = '<img src="url" class="img lazy"/><div class="wrap"><img src="url" class="img" /></div><img src="url" class="lazy" />';`

How to use regex to check in string: if not contain class "lazy" then change src to data-src?

In this case the output is:

<img src="url" class="img lazy"/><div class="wrap"><img data-src="url" class="img" /></div><img src="url" class="lazy" />
N3R4ZZuRR0
  • 2,400
  • 4
  • 18
  • 32
nhansay
  • 29
  • 1
  • 6

1 Answers1

0
preg_replace('/(?<=\<img )src(?=.+?lazy\"\>)/g', "data-src", $content);