Free parameter in striptag

1

I would like to put an exception in this function, to release insert of <iframe> . This function that I use for general forms, decreases the chance of injections, clean spaces and tags however the user wants to insert iframes of youtube, vimeo, gmaps and etc.

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

Template:

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);
}
    
asked by anonymous 14.09.2016 / 16:05

1 answer

1

You can create an anonymous function that returns strip_tags() in 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);

Output:

Array
(
    [0] => <a>asdasd</a>
    [1] => <p>dois</p>
    [2] => <iframe>2015
)
    
14.09.2016 / 16:25