本文介绍了如何转义html输入的引号(使用php)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
如果我使用预设的HTML输入,例如:
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.
我当然可以:
preg_replace('/"/', '',$lmao);但是如果我想保留该报价怎么办?
But what if I wanted to keep that quote?
推荐答案在HTML属性中输出的所有用户输入数据都应通过htmlspecialchars运行。这将对引号和其他字符进行编码:
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">';更多推荐
如何转义html输入的引号(使用php)?
发布评论