0

I have this code in my PHP page:

$regex = '/<img.*?>/';

I need that preg_match replace only images that don't have class="nopopup"

What is the correct regular expression?

Alexander van Oostenrijk
  • 4,644
  • 3
  • 23
  • 37
  • Why is this marked as a duplicate ? This question doesn't ask _HOW TO USE A DOM IN PHP_ does it ?? It asks for a _**REGEX**_ , not a DOM parsing usage question !! –  Dec 19 '19 at 18:21
  • Who marked this as a duplicate ? –  Dec 19 '19 at 18:23

1 Answers1

0

I propose a solution that avoids complicated regular expressions. Rather, keep your simple regex that looks for image elements, and use preg_replace_callback. For each match, this function will call a function defined by you and passes it that match. Then, you use a simple regular expression that scans the match for the string class="nopopup". It it's there, perform the replacement. If it's not there, you just return the original string.

Alexander van Oostenrijk
  • 4,644
  • 3
  • 23
  • 37