PHP bank text for html


I'm having trouble returning text with HTML formatting for the view . I need to return it with broken lines. I also tried to put it without the HTML tags in the database and then I used the nl2br() function that transforms /n into the tag <br> , however in both cases it returns with "" in the text as it is in the image below the firebug. I tried with different PHP functions to remove the quotes, but without success.

asked by anonymous 10.12.2015 / 13:45

3 answers


If you want to get those quotes out there you will have to do this:


Unless at the time you are printing the variable you have done so:

   <?php echo  nl2br($texto); ?>

Because in this case, the given line break in the div counts as space (which generates those quotes in the firebug interpreter).

In this case, you can do this:

<div><?php echo trim(nl2br($texto)) ?></div>

I made the following test for you to verify that my last two examples have differences:

<?php ob_start() ?>
<div>Meu nome é Wallace</div>
<?php var_dump(ob_get_clean()) ?>

<?php ob_start() ?>
    Meu nome é Wallace
<?php var_dump(ob_get_clean()) ?>

The results are:

string(31) "<div>Meu nome é Wallace</div>

string(34) "<div>
    Meu nome é Wallace

Note that these line breaks are rendered as string contents.

The first string has the underscore because I needed to break the line to put var_dump(ob_get_clean())

10.12.2015 / 13:50

If you do not see these double quotation marks in their html, the explanation of them in your element inspector is simple: Organization of the text.

As quoted in this answer: SOEN




This is just the way that chrome presents the text node content in the   element inspector. You can see white-space better this way. The quotes   are purely virtual.




This is just the way Chrome displays the content of the   text in the Item inspector. You can visualize better this way. The quotes are purely virtual.

If there are quotes in your html use trim to remove them:


$str = '"Hello"';
echo trim($str, '"'); // saída: Hello
10.12.2015 / 13:51

I believe the problem is not with the nl2br function. Check the output before applying the function to be sure. It also appears that firebug places quotation marks automatically on the console when it comes to more than one line, to improve viewing.

10.12.2015 / 13:54