模拟用户数据前端应该掌握的php基础知识
text.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="02person.php" method="post">
<input type="text" name=
'
yourname'
placeholder='请输入名字'>
<br>
<input type="submit" value="post提交">
</form>
</body>
</html>
<?php
text.php
//模拟用户数据
$personArr = array(
'jack'=>array('name'=>'jack','age'=>'28','skill'=>'摸头杀'),
'rose'=>array('name'=>'rose','age'=>'18','skill'=>'撒娇'),
'dog'=>array('name'=>'dog','age'=>'20','skill'=>'被撒狗粮'),
);
// 获取用户提交的名字
$key =
$_POST[
'
yourname'];
echo '<br>';
// 从php数据中去找这个名字,关键字
$person = $personArr[$key];
// 取值
echo '<h1>'.'用户信息'.'<br>';
echo '<h3>'.'姓名:'.$person['name'].' 年龄:'.$person['age'].' 技能是:'.$person['skill'];
?>
字符串用单引号,变量常量用双引号.
延伸:
文件的上传:
upFile.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- entype一定要有 -->
<form action="02文件上传.php" method="post"
enctype="multipart/form-data">
<input type="file" name='upFile' placeholder='' >
<br>
<input type="submit" value="提交">
</form>
</body>
</html>
upFile.php:
<?php
// sleep(2);
print_r($_FILES);
// Array ( [upFile] => Array ( [name] => me.png [type] => image/png [tmp_name] => /Applications/XAMPP/xamppfiles/temp/phpw2ZDNa [error] => 0 [size] => 64141 ) )
$key =
$_FILES['upFile'];
// 将上传的文件名字bao'cun'x
$name = $key['name'];
// 将上传的文件地址保存下来
$flocation = $key['tmp_name'];
echo $flocation.'<br>';
echo $name;
// 有的电脑上没有权限
move_uploaded_file($flocation, 'files/'.$name);
// 如何处理上传文件的限制
?>
php基础知识思维导图: