How do I escape quotes for html Input (using php)? [duplicate]

三世轮回 提交于 2019-12-23 04:50:39

问题


Possible Duplicate:
How to properly escape html form input default values in php?

If I use a preset HTML input, eg:

$lmao=$_POST['lmao'];

echo <<<EOD
<input value="{$lmao}" name="lmao" type="text">
EOD;

if a " character gets into the variable, it will result in poo, and also a data loss on re-submission.

I could, of course:

preg_replace('/"/', '',$lmao);

But what if I wanted to keep that quote?


回答1:


All user-inputted data that is being output within HTML attributes should be run through htmlspecialchars. This encodes quotes and other characters:

echo '<input value="'.htmlspecialchars($lmao).'" name="lmao" type="text">';


来源:https://stackoverflow.com/questions/11707953/how-do-i-escape-quotes-for-html-input-using-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!