HTML Tags in database

how can i save a string with html tags into database and retrive it back in php. this most likely occurs while using a ckeditor

just like you do it anyway with other strings: connect, prepare statement, query.

Try following example. I use jQuery, php
HTML

<section>
	<header>Welcome to your new home</header>
	<p>Congrats</p>
	<ol>
		<li>bed</li>
		<li>kitchen</li>
	</ol>
</section>

JSON/Jquery

var html = $(’#my_home’).html();
html = JSON.stringify(html);
$.post(‘php_file_name’, {html: html}, function(data) {
//do some things here
}

PHP
$html = htmlentities(($_POST["html"]);

You may now insert into or update the table using appropriate statement
If you check your table, all html tags will be converted to their entities.

Now to download the content of the table column to the client side (browser).
Assume table column is called lists, use html_entity_decode($row["lists"])

(if using associative array method) or html_entity_decode($row[x]) where column index is x, $row is the result of the query.

Get more information from
https://www.w3schools.com/Php/func_string_htmlentities.asp
https://www.w3schools.com/PHP/func_string_html_entity_decode.asp
http://php.net/manual/en/function.htmlentities.php
http://php.net/manual/en/function.html-entity-decode.php

Sponsor our Newsletter | Privacy Policy | Terms of Service