Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

PHP : format an html <div> to display it correctly

Hello I want to get this but when I store my div in my database and when I try to display it I can’t display it correctly can you help me?

Desired outcome:

<div data-tpl="header1" data-title="Header 1" class="drop-element"><label>LABEL 111</label></div>
<div data-tpl="header2" data-title="Header 2" class="drop-element"><input class="form-control" value="" id="changeInput" placeholder="INPUT 222"></div>

In my database :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<div data-tpl=\"header1\" data-title=\"Header 1\" class=\"drop-element\"><label>LABEL 111</label></div>
<div data-tpl=\"header2\" data-title=\"Header 2\" class=\"drop-element\"><input class=\"form-control\" value=\"\" id=\"changeInput\" placeholder=\"INPUT 222\"></div>

Display on the web page using this function on my page.php but the display is not correct :

preg_replace('/\\\\/', '', $formChaine);

unwanted result I have on the web page:

<div data-tpl="\&quot;header1\&quot;" data-title="\&quot;Header" 1\"="" class="\&quot;drop-element\&quot;"><label>LABEL 111</label></div>
<div data-tpl="\&quot;header2\&quot;" data-title="\&quot;Header" 2\"="" class="\&quot;drop-element\&quot;"><input class="\&quot;form-control\&quot;" value="\&quot;\&quot;" id="\&quot;changeInput\&quot;" placeholder="\&quot;INPUT" 222\"=""></div>

>Solution :

Everything is being escaped probably as a security measure to protect your database from sequel injection. You need to unescape it to display it. You could do it on the php side with stripcslashes when you read it from the database: https://www.php.net/manual/en/function.stripcslashes.php.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading