How do I solve the problem immediately?
It is not a gambiarra, but an option, after all gambiarra is much worse than that. You have the option to save in the database with the line breaks, I even used this technique a lot and it works, depending on your need, if you want to complicate the process a lot, or do something simplified and functional.
With STR_REPLACE trying to replace each line break with the part you want to save:
For study purposes, understanding the function used
Understanding the str_replace function used
The function str_replace () replaces some characters with others
characters in a string.
This function works by the following rules:
If the string to be searched is an array, it
will return an array
If the string to be searched is an array, find and
replace is executed with each array element
If both find and replace are arrays, and replace has less
elements to find, an empty string will be used as
replace
If locate is an array and replace is a string, the string of
substitution will be used for each value to find
Putting theory into practice
Citation used
Save to database with line breaks from:
str_replace("\n",'<brSalve no banco de dados com as quebras de linhas do <textarea>:
str_replace("\n",'<br />', addslashes(htmlspecialchars($_POST['valor']
// OPTIONAL: addslashes is for character conversion and does not give
conlflito in BD // OPTIONAL: htmlspecialchars is not allowed
special characters // To retrieve the value from the database
do so:
str_replace('<br />', "\n", $valor); />', addslashes(htmlspecialchars($_POST['valor']
// OPTIONAL: addslashes is for character conversion and does not give
conlflito in BD // OPTIONAL: htmlspecialchars is not allowed
special characters // To retrieve the value from the database
do so:
str_replace('<br />', "\n", $valor);
Observations:
PHP offers you an extensive range of opportunities to solve a problem in different ways, look for one that fits best in your programming style.
Questions, the willingness.