How to modify the text from the database?

Asked

Viewed 126 times

0

So when I request the text in the database through this instruction in php <?=converte($linha['DESCRICAO_PARA_WEB'], 0)?> the text is displayed whole block without line breaks. This function converts consists in the change of emphasis of the text and I think it does not influence anything. Here is 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 requesting it, it comes en bloc without line breaks. How to make the PHP can consider these line breaks and present them as shown in the bank?

inserir a descrição da imagem aqui

1 answer

3


To turn line breaks(\n) in <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 display source code option)

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

Browser other questions tagged

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