I want to store some html codes in mysql database , I did not do this ever before , what is the correct way to store html in db?
$html_code='<div class="hello"><p>hello world</p></div>';
// database table
part_name | html_code
hello | ??
I want to store some html codes in mysql database , I did not do this ever before , what is the correct way to store html in db?
$html_code='<div class="hello"><p>hello world</p></div>';
// database table
part_name | html_code
hello | ??
My recommend is use htmlpurifier to do it for you , sanitize input and remove all malicious code
otherwise you have to write a function like remove_special_chars($string)
for removing special chars like <
>
"
and replacing them with something like <
,>
,"
... and save to your db.
And after reading data from db use a function like add_special_chars($string)
for vice versa action to show the content. which are not easy and still non reliable