0

I'm trying to use preg_replace to remove tag and it works except for that contains another element like

<span class="img" style="margin-left:20px">
  <img src="/upload/photo/news/357/0/270x140o/688.jpg?q=1" width="250" height="125">
</span>

I use this code

echo preg_replace('/<span[^>]*>.*?<\/span>/i', '', $txt);

which contains text gets removed and text too but not containing the image. How to modify the code to remove the with the too?

PHP User
  • 2,350
  • 6
  • 46
  • 87
  • use [nodeValue](https://www.php.net/manual/en/class.domnode.php) – Lawrence Cherone Sep 28 '19 at 12:56
  • Regular expressions are _not_ able to reliably process HTML markup. That is one of the first basic things one understands when diving into complexity theory. Use a DOM parser for this job. Using regular expressions will lead you down a path of endless frustration for endless exceptions. – arkascha Sep 28 '19 at 13:02

0 Answers0