-----
本系列由<PHP从入门到精通>后面习题构造
----
1.动态网页的特点是能够人机交互,但有时却需要限制用户的输入.使用网页中post方式判断网页text框中的数据是否满足一下条件:
1)输入必须为全数字
2)输入字符串不允许超过25
3)输入不能为空
HTML:
<!DOCTYPE html>
<html>
<head>
<title>task</title>
</head>
<body>
<form method="post" action="1.php">
<h1>task 1:</h1>
<label>请输入内容:</label>
<input type="text" name="content">
<input type="submit" />
<input type="reset" />
</form>
</body>
</html>
PHP:
<?php
if ($_POST['content']==null){
echo "输入不能为空";
}else if (!is_numeric($_POST['content'])){
echo "输入要为全数字";
}else if (strlen($_POST['content'])>25) {
echo "字符串长度不允许超过25";
}
?>
<?php
echo "主机名:".$_SERVER['SERVER_NAME']."<br />";
echo "User-Agent:".$_SERVER['HTTP_USER_AGENT']."<br />";
echo "来访者IP:".$_SERVER['REMOTE_ADDR']."<br />";
echo "端口:".$_SERVER['REMOTE_PORT']."<br />";
echo "服务器端口".$_SERVER['SERVER_PORT']."<br />";
?>
参考:http://php.net/manual/zh/reserved.variables.server.php
3.PHP中输出语句有echo,print,printf,print_r.尝试用这4个语句输出数据,看它们之间的区别
<?php
$a="abc123";
echo $a."<br />";
print($a)."<br />";
printf("%s",$a)."<br />" ;
echo "<br />".print_r($a,true);
?>
参考:php输出echo、print、print_r、printf、sprintf、var_dump的区别比较_php技巧_脚本之家