0

Knowing that:

$str = $row_ultimos_posts['conteudo'];

I have this code:

echo preg_replace("/<iframe[^>]+\>/i", "",$str);

And I have this code:

preg_replace ("/<img(.+?)>/", "",$str);

How can I use both codes? How to merge it to work?

  • 1
    `preg_replace('/<(iframe|img)(.*?)>/', '', $str);` But [don't parse html with regular expressions](http://stackoverflow.com/a/1732454/418413). – kojiro Aug 31 '14 at 20:49
  • 1
    It occurs to me that this will remove the opening iframe/img tag, but not the closing one. Just one more argument against parsing html with regular expressions. – kojiro Aug 31 '14 at 20:57
  • Regex is probably the wrong approach here. [See this question](http://stackoverflow.com/questions/7072327/strip-tags-function-blacklist-rather-than-whitelist) (related) – scrowler Aug 31 '14 at 20:58

2 Answers2

0
preg_replace("/<iframe[^>]+\>/i", "",preg_replace ("/<img(.+?)>/", "",$str));
Khairu Aqsara
  • 1,321
  • 3
  • 14
  • 27
-1

You can basically wrap them in a function like

function foo($str)
{

$str = preg_replace("/<iframe[^>]+\>/i", "",$str);
$str = preg_replace ("/<img(.+?)>/", "",$str);

return $str;

}
John Dave Decano
  • 128
  • 1
  • 1
  • 5