如何在PHP中正确地转义html表单输入默认值? [英] How to properly escape html form input default values in php?

查看:107
本文介绍了如何在PHP中正确地转义html表单输入默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出以下两个html / php片段:

< input type =textname =firstnamevalue =<<< ;?php echo $ _POST ['firstname'];?> />





< textarea name =content><?php echo $ _POST ['content']; ?>< / textarea>



什么字符编码需要用于回显 $ _ / code>变量?我可以使用任何内置的PHP函数吗?请假定 $ _ POST 值尚未编码。

解决方案

使用 htmlspecialchars($ _ POST ['firstname']) code>和 htmlspecialchars($ _ POST ['content'])

在将它们展示给用户之前,一个href =http://php.net/htmlspecialchars> htmlspecialchars()


Given the following two html/php snippets:

<input type="text" name="firstname" value="<?php echo $_POST['firstname']; ?>" />

and

<textarea name="content"><?php echo $_POST['content']; ?></textarea>

what character encoding do I need to use for the echoed $_POST variables? Can I use any built in PHP functions? Please assume that the $_POST values have not been encoded at all yet. No magic quotes no nothing.

解决方案

Use htmlspecialchars($_POST['firstname']) and htmlspecialchars($_POST['content']).

Always escape strings with htmlspecialchars() before showing them to the user.

这篇关于如何在PHP中正确地转义html表单输入默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆