Release parameter on striptag

Asked

Viewed 26 times

1

I would like to put an exception in this function, to release insertion of <iframe>. This function that I use for general Forms, decreases the chance of injections, clears the spaces and tags but the user wants to insert youtube iframes, Vimeo, Gmaps and etc.

I tried to apply this example without success, where I am missing?

Model:

echo strip_tags($text, '<p><a>');

Function:

//Valida e cria os dados para realizar o cadastro
private function setData() {

    $this->Data = array_map('strip_tags', $this->Data);
    $this->Data = array_map('trim', $this->Data);
}
  • The problem is to pass the argument on array_map()?

  • the problem is declaring which tags I want to release when applying striptags

  • wanted to do something like this, but it gives clear error, wanted to know how to apply correctly. $this->Data = array_map('strip_tags', $this->Data,'<iframe>');

1 answer

1


You can create an anonymous function that returns the strip_tags() in the array_map().

$tags = '<a><p><iframe>';
$arr = ['<a>asdasd</a>', '<p>dois</p>', '<iframe>2015</iframe'];

$novo = array_map(function($item)use($tags){return strip_tags($item, $tags);}, $arr);

Exit:

Array
(
    [0] => <a>asdasd</a>
    [1] => <p>dois</p>
    [2] => <iframe>2015
)
  • So rray, I want q in the array answer to have <iframe>

  • 1

    @Brunocoio edited the answer, lacked a detail before.

  • That’s right, that’s right, thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.