1
votes

I am using Bootstrap Summernote in form. I insert the data via Jquery-Ajax in php. Now i have one paragraph which i am entering in Summernote Editor. Which i want to convert the special characters which is entered in Editor.

Editor Content Like Below :

“Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ac ullamcorper enim. Nam consectetur aliquam consequat. Quisque in odio in lorem porta vehicula et eget quam”

Vivamus ornare ante vel tincidunt efficitur. Ut et semper diam, non aliquet elit. Nunc vulputate gravida magna. Vivamus malesuada, nisl ac placerat ultricies - purus ligula venenatis neque, et tristique massa urna id risus. Nam laoreet, dui ut congue elementum, sapien lectus congue tortor, a aliquam lorem sapien mattis arcu. Mauris dapibus lorem eleifend lacus euismod faucibus. Nullam congue, dolor nec tempor feugiat, quam ligula congue lacus, sit amet aliquet orci velit id turpis.

How should i encode this text to store in the database and decode for view in html page as same as paragraph? My concern is how to encode-decode special character in php-mysql?

2

2 Answers

0
votes

In MySQL you have TEXT and BLOB types which are used for storing big amount of data.

The difference with VARCHAR is that those are stored off the table in some external location and are just referred to by a pointer from the record. Hence they are slower than VARCHAR but with the plus side of allowing you to store more data. The mentioned types can contain data with max length 2^16 byte. If you need to store more data you have LONGBLOB, LONGTEXT that go up to 2^32.

0
votes

Just a head up, if this is going to be a public site, I recommend you read and understand SQL Injection and Cross-site scripting (XSS) attacks before deploying any build to production that allows for user input. The following functions will not take either into consideration.

To store the text content safely AS IS, you could use the following create_safe_string function to make the string SQL safe on INSERT, and create_unsafe_string when displaying the content again:

    function create_safe_string($root)
    {
        return htmlentities(trim(str_replace("\\", "", $root)), ENT_QUOTES | ENT_IGNORE, "UTF-8", true);
    }

    function create_unsafe_string($root)
    {
        return html_entity_decode(trim($root), ENT_QUOTES, "UTF-8");
    }