问题
How to strip HTML tags, but not all tags? For example i want to have <br>
, <b>
etc in textareas.
I have this form validation rule:
$this->form_validation->set_rules('user_desc', 'Opis', 'min_length[3]|max_length[200]|xss_clean|strip_tags');
回答1:
Use strip_tags() with the second argument.
$stripped = strip_tags($str, '<b><br>');
You could build an array of allowable elements and then join them for the second argument with...
$allowedElementsJoined = '<' . implode('><', $allowedElements) . '>';
回答2:
Use
strip_tags($string, '<b><br>');
In second parameter you include all the allowed tags.
来源:https://stackoverflow.com/questions/7298944/how-to-use-strip-tags-with-second-parameter-in-codeigniter