Delete line breaks in an echo in PHP

2

I have a html / php page that receives data in a textarea and saves it to a mysql database.

Sometimes the user uses line break in their text and saves in the good bank.

I also have a php page that converts any record to json, link , which can be read for an android app I'm developing.

However, when there is a line break, the app gives json reading problems.

If you click the link above, you will see that the value of the descricao key is like this: Tudo em moda masculina. Os melhores preços você encontra aqui! Venda via Instagram. Here it does not show, but after the exclamation, there is a line break before the text 'Sale via Instagram'. It is not easy to solve, because I do not know how to "catch" this line break

How to do in php to ignore the line break in a mysql database when generating a echo , eg:

echo semQuebraDeLinha($linha['dado']);
    
asked by anonymous 28.03.2018 / 01:22

1 answer

2

Then try to perform a search for a regular expression and replace it by clearing \r carriage return and \n Newline. See:

preg_replace( "/\r|\n/", "", $linha['dado'] );

If the match is found, the new subject ($ line ['given']) will be returned, otherwise subject will be returned unchanged or NULL if an error occurred. source: php.net

    
28.03.2018 / 03:12