M
M
Millerish2018-02-26 14:03:51
PHP
Millerish, 2018-02-26 14:03:51

How to save to db \n?

Good afternoon!
I need to save and display a multi-line string (textarea) from the database. How to do it right?
Now when sending:
1) I pass the string (HTML->JS->PHP) via fetch
2) I get the string (PHP) via $_GET, I write the data to the database (INSERT)
Now when I receive it:
1) I make a request (JS->PHP ) via fetch
2) receive and return (PHP->MYSQL->PHP) - print_r(json_encode($res, JSON_UNESCAPED_UNICODE))
3) output to textarea(PHP->JS->HTML)
Everything works, but when outputting multiline text hyphens are lost (all in one line). How to correctly display multiline text?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Millerish, 2018-02-26
@Millerish

encodeURIComponent

F
FeNUMe, 2018-02-26
@FeNUMe

\n is as much a part of a string as text, so watch where it gets lost. I suspect it's around here

json_encode

M
Maxim Timofeev, 2018-02-26
@webinar

I get a string (PHP) via $_GET, I write data to the database (INSERT)

Who does that, Carl? If there is a record in the database only POST and for a number of reasons related to security, standards, common sense, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question