PHP bank text for html

6

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 let 10.12.2015 в 13:45
source

3 answers

7

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

 trim(nl2br($texto));

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

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

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() ?>
<div>
    Meu nome é Wallace
</div>
<?php var_dump(ob_get_clean()) ?>

The results are:

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

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

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())

    
answered by 10.12.2015 / 13:50
source
2

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

  

Original

     

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.

     

Translation

     

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:

Example:

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

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.

    
answered by 10.12.2015 в 13:54