php如何实现表单数据验证-PHP问题

资源魔 39 0

php若何完成表复数据验证

起首经过“trim()”函数去除了用户输出数据中不用要的字符 (如:空格,tab,换行);

示例:

$text   = "\t\tThese are a few words :) ...  ";
$binary = "\x09Example string\x0A";
$hello  = "Hello World";
var_dump($text, $binary, $hello);

print "\n";

$tri妹妹ed = trim($text);
var_dump($tri妹妹ed);

$tri妹妹ed = trim($text, " \t.");
var_dump($tri妹妹ed);

$tri妹妹ed = trim($hello, "Hdle");
var_dump($tri妹妹ed);

// 肃清 $binary 首位的 ASCII 管制字符
// (包罗 0-31)
$clean = trim($binary, "\x00..\x1F");
var_dump($clean);

输入后果:

string(32) "        These are a few words :) ...  "
string(16) "    Example string
"
string(11) "Hello World"

string(28) "These are a few words :) ..."
string(24) "These are a few words :)"
string(5) "o Wor"
string(14) "Example string"

而后应用“stripslashes()”函数去除了用户输出数据中的反斜杠;

示例:

$str = "Is your name O\'reilly?";

// 输入: Is your name O'reilly?
echo stripslashes($str);

最初正在挪用“htmlspecialchars()”函数将HTML代码进行本义。

咱们对用户一切提交的数据都经过 PHP 的 htmlspecialchars() 函数解决。

当咱们应用 htmlspecialchars() 函数时,正在用户测验考试提交如下文本域:

<script>location.href('http://www.runoob.com')</script>

该代码将没有会被执行,由于它会被保留为HTML本义代码,以下所示:

&lt;script&gt;location.href('http://www.runoob.com')&lt;/script&gt;

以上代码是平安的,能够失常正在页面显示。

以上就是php若何完成表复数据验证的具体内容,更多请存眷资源魔其它相干文章!

标签: php php教程 stripslashes php故障解决 php使用问题 trim htmlspecialchars

抱歉,评论功能暂时关闭!