How to modify the text coming from the database?

0

Then, when I do the request of the text in the database through this statement in php <?=converte($linha['DESCRICAO_PARA_WEB'], 0)?> the text is presented all in block without the line breaks. This function converts is the change in accentuation of the text and I think it does not influence anything. Here's the function:

# Função para conversão de caracteres
function converte($string, $tp){
    if ($tp == "1") 
    $palavra = strtr(utf8_encode($string) ,
    "àáâãäåæçèéêëìíîïðñòóôõö÷øùüúþÿ" ,"ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÜÚÞß");
    elseif ($tp == "0")
    $palavra = strtr(utf8_encode($string) ,
    "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÜÚÞß","àáâãäåæçèéêëìíîïðñòóôõö÷øùüúþÿ");
    return $palavra;
}

As I was saying the text is presented this way in the database but when you request it, it comes in block without the line breaks. How can PHP consider these line breaks and display them as shown in the bank?

    
asked by anonymous 03.10.2014 / 16:43

1 answer

3

To turn line breaks ( \n ) into <br> use the function nl2br

<?php
$str =  "IMPERDÍVEL!

Localizada no melhor endereço do Chácara
das Pedras em rua plana e de fácil acesso.

Casa aconchegante,";

echo nl2br($str);

Browser output: (see option to view source code)

IMPERDÍVEL!<br />
<br />
 Localizada no melhor endereço do Chácara<br />
 das Pedras em rua plana e de fácil acesso.<br />
<br />
 Casa aconchegante,

Example

    
03.10.2014 / 16:52