最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

php如何实现表单数据验证

来源:动视网 责编:小采 时间:2020-11-03 12:31:34
文档

php如何实现表单数据验证

php如何实现表单数据验证:php如何实现表单数据验证首先通过trim()函数去除用户输入数据中不必要的字符 (如:空格,tab,换行);示例:$text = "\t\tThese are a few words :) ... "; $binary = "\x09Example string\x0A&quo
推荐度:
导读php如何实现表单数据验证:php如何实现表单数据验证首先通过trim()函数去除用户输入数据中不必要的字符 (如:空格,tab,换行);示例:$text = "\t\tThese are a few words :) ... "; $binary = "\x09Example string\x0A&quo

php如何实现表单数据验证

首先通过“trim()”函数去除用户输入数据中不必要的字符 (如:空格,tab,换行);

示例:

$text = "	These are a few words :) ... ";
$binary = "x09Example stringx0A";
$hello = "Hello World";
var_dump($text, $binary, $hello);

print "
";

$trimmed = trim($text);
var_dump($trimmed);

$trimmed = trim($text, " 	.");
var_dump($trimmed);

$trimmed = trim($hello, "Hdle");
var_dump($trimmed);

// 清除 $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转义代码,如下所示:

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

以上代码是安全的,可以正常在页面显示。

文档

php如何实现表单数据验证

php如何实现表单数据验证:php如何实现表单数据验证首先通过trim()函数去除用户输入数据中不必要的字符 (如:空格,tab,换行);示例:$text = "\t\tThese are a few words :) ... "; $binary = "\x09Example string\x0A&quo
推荐度:
标签: 验证 数据 php
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top