0

I'm using Ckeditor to allow people to format text and then insert in database using mysqli parametized query as follow :

 if (isset($_POST['editor1'])) {

     $editor1 = htmlentities($_POST['editor1']);

     //insert variables in table blog_post
     $insert_blog_post_q= $conn->prepare("INSERT INTO blog_posts (blog_body) VALUES (?)");
     $insert_blog_post_q->bind_param('s',$editor1);
     $insert_blog_post_q->execute();
     $insert_blog_post_q->close();
    }

When I output the results it creates r\n problems in between the paragraphs as follow

 Hello im a title
 r\n
 More text
 r\n
Text text
 r\n

This problems will also creates back lashes in img src like this :

<img src='\"https://myimage.com"\'>

This will cause all the image links to be broken.

How can i fix this problem? Thank you

Sadie
  • 163
  • 10
  • It sounds like you're running `addslashes()` somewhere. – Alex Howansky Nov 07 '18 at 14:42
  • Why do you use `htmlentities()` before you store it in the database? And how do you display the results you get from the database? – jeroen Nov 07 '18 at 14:42
  • Possible duplicate of [How to stop CKEditor producing \r\n characters automatically when data is sanitized in PHP?](https://stackoverflow.com/questions/25112124/how-to-stop-ckeditor-producing-r-n-characters-automatically-when-data-is-saniti) – Alexandre Elshobokshy Nov 07 '18 at 14:43

1 Answers1

1

This was not duplicate for me honestly I did not find all the answers to my problems in the suggestions above. However I did solve my problem with the manual.

I output mysqli select result as follow :

//fix r\n from blog post body
$blogpostbody = str_ireplace(array("\r","\n",'\r','\n'),'', $blog_p['post_body']); 

//remove backlashes that cause pictures to be broken
$blogpostbodynolashes = stripslashes($blogpostbody);
Sadie
  • 163
  • 10