php
前提须知
php是弱类型的脚本语言[1]
虽然在html里面使用php但是前端通过开发者工具是看不到的
使用echo输出
1
echo "<h1>标题</h1>"
变量
由于是弱语言所以我们只需要$
进行操作就行了
使用16进制
1
$hex=0x16
使用判断
===
字符串类型
拼接符号
1
2
3$c="hhh";
$d="dada";
echo $c.$d部分字符串处理的函数
1
2
3
4
5
6
7
8
9
10
11//计算字符串的长度
echo "<br>";
echo strlen($c.$d);
//反转字符串
echo "<br>";
echo strrev($c.$d);
//从查找strpos()
echo strpos($c,"h");
//替换
echo "<br>";
echo str_replace("h","e",$c)其他的函数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17//计算字符串的长度
echo "<br>";
echo strlen($c.$d);
//反转字符串
echo "<br>";
echo strrev($c.$d);
//从查找strpos()
echo strpos($c,"h");
//替换
echo "<br>";
echo str_replace("h","e",$c)."<br>";
//ceil 向上取整
echo ceil(3.4)."<br>";
//向下取整
echo floor(4.2)."<br>";
//取随机整数
echo rand(2,10);从前端获取输入
我们需要使用
html
的form
表单形式1
2
3
4
5
6
7
8
9
10
11
12
13<form action="" method="get">
<label for="id:"></label>
<input type="number" name="id"><br>
<label for="passwd:"></label>
<input type="number" name="passwd"><br>
<input type="submit" name="submit">
</form>
<?php
echo $_GET['id']."<br>";
echo $_GET['passwd'];
?>使用_GET方法获取,因为表单的提交方法是get
计算机:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16<!-- 计算器 -->
<form action="" method="get">
input num1:
<input type="number" name="num1"><br>
input num1:
<input type="number" name="num2"><br>
<input type="submit">
</form>
<?php
echo "result is:";
echo $_GET['num1']+$_GET['num2'];
?>
数组
创建数组&输出特定的元素
1 |
|
当直接输出数组的名称的时候,就会输出类型
增加元素
1 |
|
使用数组接受
1 |
|
文件包含
语法
1
2include 'filename';
require 'filename';
类与对象
1 |
|
- 解释语言,不需要编译 ↩
php
https://tsy244.github.io/2023/10/11/PHP/php/