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')
1 - from www 2 - from wp rest api
I want the same as 1.
tag to break lines. However if you are using a textarea for display, you should look at this answer, in particular the css solution: https://stackoverflow.com/questions/8627902/how-to-add-a-new-line-in-textarea-element – gview Oct 05 '22 at 19:09
`. You'll want to encode it with https://www.php.net/manual/en/function.htmlspecialchars.php , since it looks like it's accepting json, it might be better to create an array and json_encode it. See https://stackoverflow.com/questions/11079135/how-to-post-json-data-with-php-curl for directions on that – aynber Oct 05 '22 at 19:12