Reputation: 441
I'm integrating TinyMCE (V 4.8.2) into a web app were users can create their own webpages on a server. We are saving everything to a MySQL Database.
What is the proper way to prepare the data to be saved into the database and then to pull it from the database later and display it?
I tried to prepare it for the save by running this code:
$pageContent = $mysqli->real_escape_string($_POST['pageContent']);
When I pull it from the database, I display it back in the TinyMCE Editor using this code:
htmlspecialchars($pageContent)
The problem is, it's adding \r\n to the display.
What is the proper way to save and display the data from TinyMCE?
Thanks! Rick
Upvotes: 0
Views: 1093
Reputation: 2407
\r\n is new line in html and it is read by tinymce.... to remove these, you will need stripslashes.
you can try
$pageContent = stripslashesh(str_replace('\r\n', '',$mysqli->real_escape_string($_POST['pageContent'])));
only stripslashes will convert \r\n to 'rn' which will be stored as text... so str_replace can be used to remove whole \r\n..
Upvotes: 1