简体   繁体   中英

PHP form escapes html field after submit

I have the following problem.

I am using a form to submit a textarea which includes HTML tags.

<div style="width:100%;display:block;float:left;">
   <p>Name: <strong>test</strong><br />
   Address: <strong>address</strong><br />
   Date:<strong> 09/12/2014</strong></p>
</div>

However, when I submit the form via POST I get the following result:

   div style=width:100;display:block;float:left; pName: strongΓΕΩΡΓΙΑ ΙΩΑΝΝΗΣ ΓΕΩΡΓΙΑΔΗ/strongbr / Address: strongΟΔΟΣ ΠΕΝΤΕΛΗΣ 110 , 15231 ΜΑΡΟΥΣΙ, Greece/strongbr / Date:strong 09/12/2014/strong/p /div

PHP magic quotes are

When I was trying that on my development machine it was working fine, but now that I moved it to a dedicated server is not working as it should.

Can you please help?

You can try this:

Use htmlspecialchars($_POST['html'], ENT_QUOTES) and when you echo it again (from database) use htmlspecialchars_decode($result['html'])

http://php.net/manual/en/function.htmlspecialchars.php

If i use:

<?php
if(isset($_POST['send'])){
    $html = htmlspecialchars($_POST['html']);
    echo $html;
    echo htmlspecialchars_decode($html);
}
?>
<form method="POST">
    <textarea name="html">

    </textarea>
    <input type="submit" name="send" value="Send" />
</form>

It works, so maybe it's something with your database?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM