1. Experimental hours
2 hours
2. Experimental purpose
1. Become more familiar with Web page design technology;
2. Master the basic syntax of PHP;
3. Master PHP data types and operations.
3. Experimental equipment
PC computer, equipped with Win10 operating system, Word2019, PHPStudy+eclipse for php
4.Experimental content and procedures
( 1 ) Experimental steps
①New Project File—new—Local PHP Project
②Create two new php files, right-click on the project—new—PHP File
③Enter the code and save it
④Verify the correctness of the code in the browser and output the running results
(2) Experimental content
1) Implement the interface shown below.
Click the OK button to shift the data in the Input to achieve data encryption.
When the variable is $c, $c<<i. When i is 5, it means shifting 5 bits to the left. The value of i is customized.
Source code: 202011110057_2_2_1.php
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>数据加密</title>
</head>
<body>
184
<form name="form" method="post" action=""> <!-- 提交到当前php文件处理 -->
<tr>
<td>数字口令:</td>
<td><input type="text" value="23" name="num"></td>
<td><input type="submit" value="确定"></td>
</tr>
</form>
<?php
if (isset($_POST['num']) && is_numeric($_POST['num'])){
//isset:判断变量存不存在;is_numeric判断是不是数值
$a = $_POST['num'];
$b = $a<<3;
echo $b;
}
else
echo "no number";
?>
</body>
</html>
Result screenshot:
2) The web page outputs the multiplication table
Source code: 2_2_2.php
<?php
for($i = 1 ; $i <= 9 ; $i++){
for($j = 1 ; $j <= $i ; $j++){
//for循环,保证第i行,有i个算数式
echo $j."*".$i."=".$i*$j." "." ";//输出语句,字符之间用 “.” 连接
}
echo "</br>";//每一行一个换行符
}
?>
Result screenshot:
5. Experimental results
Through this experiment I learned:
- The action in the form represents the submitted url address. It is empty by default or $_PHP_SELF represents the submission to the current web page.
- The isset() method is used to determine whether the variable exists.
- The is_numeric() method is used to determine whether a variable is a number.
- $_POST["num"], obtains the variable value named num in the input tag of the request form.