Search code examples
phpmysqlwordpress-rest-apicodeigniter-4

Insert string with \n to mysql


I'm tring create a comment by Wordpress Rest API and I have a problem.

Creating works but I can't save comment with break lines.

In database I have:

line 1\nline 2\nline 3

What can I do before post request with text?

Is there any function in php that will add break lines instead of \n?

@edit

This is my curl post:

$parameters = '?post=' . $this->request->getVar('eventId') . '&content=' . $this->request->getVar('content');

            if ($this->request->getVar('authorName')) {
                $parameters .= '&author_name=' . $this->request->getVar('authorName');
            }

            try {
                $apiComment = $curl->post('https://xxxx.xx/wp-json/wp/v2/comments' . $parameters, [
                    'headers' => [
                        'Accept' => 'application/json'
                    ]
                ]);

This is from another api and it's string:

$this->request->getVar('content')

enter image description here

1 - from www 2 - from wp rest api

I want the same as 1.


Solution

  • It's solution:

    str_replace(['\n'], '%0D%0A', $this->request->getVar('content'))