多维数组的创建、数组的遍历:
详细代码:
<meta charset = 'utf-8'/> <?php //使用array()语句结构将列表中所有数据声明为一个二维数组,默认下标是顺序数字索引 $contact1 = array( //定义外层数组 array('Feng_Blue','1','19','176'),//子数组1 array('Feng_Pink','0','23','176'),//子数组2 array('Feng_Red','0','21','176'), //子数组3 array('Feng_Black','1','20','176') //子数组4 ); //以HTML表格的形式输出二维数组中的每个元素 echo '<table border="1" width="600" align="center",>'; echo '<caption><h1>学生信息</h1></caption>'; echo '<tr bgcolor="#dddddd">'; echo '<th >姓名</th><th>性别</th><th>年龄</th><th>身高</th>'; echo '</tr>'; //使用双层for语句嵌套二维数组$contact1,以HTML表格的形式输出 //使用外层循环遍历数组$contact1中的行 for($row=0;$row<count($contact1);$row++) { echo '<tr align="center">'; //使用内层循环遍历数组$contact1 中 子数组的每个元素,使用count()函数控制循环次数 for($col=0;$col<count($contact1[$row]);$col++) { echo '<td>'.$contact1[$row][$col].'</td>'; } echo '</tr>'; } echo '</table>'; ?>
结果:
四种方法传递POST 参数并接收:
利用表单:
详细代码:
<html> <head> <meta charset = 'utf-8'/> </head> <body> <?php if(empty($_POST['submit'])){ ?> <h1>收租信息</h1> <form action = "" method = "post" enctype = "application/x-www-form-urlencoded" > 账号: <input type = 'text' name = "username"/><hr /> 密码: <input type = 'password' name = "password"/><hr /> <input type = 'submit' name = "submit" value = "登录"/> </form> <?php }else{ echo "您输入的用户名是{$_POST['username']},您输入的密码是{$_POST['password']}!"; } ?> </body> </html>
hackbar:
BP:
python:
详细代码:
C:\Users\11962>python Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import requests >>> url = "http://192.168.8.135/php/9.27/post.php" >>> data = {'username' : 'FengBlue','password' = 'Feng','submit' : 'submit'} File "<stdin>", line 1 data = {'username' : 'FengBlue','password' = 'Feng','submit' : 'submit'} ^ SyntaxError: invalid syntax >>> data = {'username' : 'FengBlue','password' : 'Feng','submit' : 'submit'} >>> res = requests.post(url = url, data = data) >>> res.content.decode('utf-8') "\r\n<html>\r\n\t<head>\r\n\t<meta charset = 'utf-8'/>\t\r\n\t</head>\r\n\t<body>\r\n您输入的用户名是FengBlue,您输入的 密码是Feng!\r\n\t</body>\r\n</html>"
编写一个PHP 脚本用来接收cookie 参数
信息代码:
<?php var_dump($_COOKIE); ?>
结果:
验证预定义超全局数组的作用
$GLOBALS
详细代码:
<?php $username = 'Feng_Blue'; $password = 'Feng'; var_dump($GLOBALS); ?>
结果:
$_SERVER
详细代码:
<?php var_dump($_SERVER); ?>
$_GET
详细代码:
<?php var_dump($_GET); ?>
结果:
$_REQUEST
详细代码:
<?php var_dump($_REQUEST); ?>
结果:
验证数组相关函数的用法:
count:
详细代码:
<?php $Feng = array('qwq','qaq','@.@','ovo'); echo count($Feng); ?>
结果:
array_count_values
详细代码:
<?php $array = array("Feng", "Jie", "love", "@.@", "Feng"); print_r(array_count_values($array)); ?>
结果:
in_array()
详细代码:
<?php $array = array('Feng', 'Jie', 'love', '@.@', 'Feng'); var_dump(in_array('Feng',$array)); ?>
array_search()
详细代码:
<?php $array = array('Fens', 'Jie', 'love', '@.@', 'Feng'); var_dump(array_search('Feng',$array)); ?>
array_key_exists()
详细代码:
<?php $array = array("Feng", "Jie", "love", "@.@", "Feng"); var_dump(array_key_exists(8,$array)); ?>
利用$_FILES 实现php 语言的文件上传完整功能
详细代码:
<?php header("Content-Type:text/html; charset=utf-8"); $html = <<<tat <html> <head> <meta charset = 'utf-8'> </head> <body> <form enctype="multipart/form-data" method="post"> <input type = "file" name = "upfile" /> <input type = "submit" name = "submit"/> </form> </body> </html> tat; if(empty($_POST['submit'])){ echo $html; }else{ $tmpP = $_FILES['upfile']['tmp_name']; $desP = './oooo/'.$_FILES['upfile']['name']; if(move_uploaded_file($tmpP,$desP)){ echo "YES"; }else{ echo "NO"; } } ?>