Take all html tags minor to line break

Asked

Viewed 571 times

2

My doubt is simple, I think.

I receive via post the description:

    $descricao = strip_tags(mysql_escape_string(trim($_POST['descricao'])));

And when I print on the screen I use:

    nl2br($foto_user_visitado->descricao)

This should print on the screen the description recognizing the "enter" but how I put the function strip_tags it does not show. How can I do? being that I want to escape all tags html.

  • You can adapt the code using htmlentities($str); instead of strip_tags and then use other methods to remove tags.

  • You want to keep line breaks or tags br?

1 answer

1

If the line break is the tag <br /> just put a second parameter in the strip_tags function and in it you will indicate which tags should be kept.

For example:

<?php

//somente as tags <br> e <i> serão mantidas
$texto = strip_tags("<b>texto</b> com<br /><i>tags</i><br />html", '<br><i>');

echo $texto;

Will return:

text with
tags
html

Browser other questions tagged

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