2
I have an html/php page that receives data in a textarea and saves it in a mysql database.
Sometimes the user uses line break in his text and saves in the good database.
I also have a php page that converts any record into json, https://buscafree.com.br/listaDetalhe.php?id=1, that can be read by an android app I’m developing.
However, when there is some line break, the app gives problem reading json.
If you click on the link above, you will see that the key value descricao
is like this: Tudo em moda masculina. Os melhores preços você encontra aqui! Venda via Instagram.
It does not show here, but after the exclamation, there is a line break before the text 'Sale via Instagram'. It’s not easy to solve, because I don’t know how to "catch" this line break
How to do php to ignore line breaking in a mysql database when generating a echo
, example:
echo semQuebraDeLinha($linha['dado']);
Tried to
$v = str_replace("\n"," ", $linha['dado'])
orpreg_replace('/\s/',' ',$string);
– rbz
@RBZ, did not work since line breaks are not saved in the bank by n
– Italo Rodrigo
Then remove in select with
replace
... tried ?– rbz
I used the function nl2br() that added in the text stored in the BD Mysql the text with several <br />. Even so, next to these breaks, line breaks still persisted... then, after the above function, I used str_replace(), changing the breaks - char(10) - by <br>... the text was then stored with two lines breaks <br /> and <br>, next to each other, meaning that even using the nl2br function, still persisted a line break type Chr(10)... to return the text to the screen with only one break per line, I used str_replce to remove one of the <br>.
– rbz
See this other one too. Replacing the char(10)...
– rbz
You tried to preg_replace like this:
preg_replace( "/\r|\n/", "", $linha['dado'] );
– Fabiano Monteiro
the point is that the text appears normal, with no symbol indicating the line break :/
– Italo Rodrigo
add the question as to the text
– Costamilam
@Added guilhermecostamilam
– Italo Rodrigo
@RBZ think it should work with char(10), but I’m not understanding how to use it. can give an example?
– Italo Rodrigo
In mysql it appears 2 strange "squares". I already asked a question and put an image of it. I’m on my cell phone, I can’t test it now, but tomorrow I’ll test it and tell you.
– rbz
Sorry guys, I solved with the @Fabianomonteiro tip: preg_replace( "/ r| n/", "", $line['given'] ); If you want to receive the points just post the answer. hug
– Italo Rodrigo