和大家分享一下小弟我学php的前两个小时成绩(适合菜鸟)(散分)
和大家分享一下我学php的前两个小时成绩(适合初学者)(散分)
学习自:
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->http://www.w3school.com.cn/php/
1.php 文件必须是:
语句在这里写
?>
2.echo 输出函数 方法:echo “abc”
3.定义变量:$变量名 = 变量值
4.两个变量联合输出用“.”连接 例如:echo $变量1.变量2
5.strlen()函数是表示 变量值的长度
例如echo strlen(“Hello world!”);输出12
6.strpos()函数表示检索字符串 查找字符串在某个字符串中的位置
7.运算符
算数运算符
运算符 说明 例子 结果
+ Addition x=2
x+2 4
- Subtraction x=2
5-x 3
* Multiplication x=4
x*5 20
/ Division 15/5
5/2 3
2.5
% Modulus (division remainder) 5%2
10%8
10%2 1
2
0
++ Increment x=5
x++ x=6
-- Decrement x=5
x-- x=4
赋值运算符
运算符 说明 例子
= x=y x=y
+= x+=y x=x+y
-= x-=y x=x-y
*= x*=y x=x*y
/= x/=y x=x/y
.= x.=y x=x.y
%= x%=y x=x%y
比较运算符
运算符 说明 例子
== is equal to 5==8 returns false
!= is not equal 5!=8 returns true
> is greater than 5>8 returns false
>= is greater than or equal to 5>=8 returns false
逻辑运算符
运算符 说明 例子
&& and x=6
y=3
(x 1) returns true
|| or x=6
y=3
(x==5 || y==5) returns false
! not x=6
y=3
!(x==y) returns true
8.函数date("D");时间函数 返回当天信息
9.定义集合:$name = array(“刘文成”,”程海燕”,”myPHP”);
10.for循环
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$i=0; for($i=1;i”;}
11.foreach 循环
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$arr = array(“one”,”two”,”three”); foreach($arr as $value){ echo “我变了集合项目”.$value}
12.函数定义关键字:function
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php function w(){ echo “liuwencheng”;}echo “我的名字是:”;w();?>
13.function w($name1,$name2)--=>放参数
14.在函数中return用于返回值
15.$_POST[“name”]或者$_GET[“name”]是获得表单提交的值
16. $_COOKIE[“name”]获得cookie的值
17.$_REQUEST[“name”]包含了$_POST $_GET $_COOKIE
18.data(format,timesamp);
函数含义:时间
参数含义:format:必须,规定时间的格式
Timesamp
例子:echo data(“y/m/d”) ;
echo data(“y.m.d”);
echo data(“y-m-d”);
以上输出:
2006/07/11
2006.07.11
2006-07-11
19. mktime(hour,minute,second,month,day,year,is_dst)
函数含义:时间点
Is_dst是可选参数 其他参数可选
20.include(“head.php”)函数
设置 head.php 文件为页眉文件
例如:
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php include("header.php"); ?><h1 id="Welcome-to-my-home-page">Welcome to my home page</h1><p>Some text</p>
21.require(“head.php”)函数
与include()函数几乎一样 只是错误的处理方式不一样
include除了错还会执行后面的php代码 而require则立即返回
22.fopen();在php页面中打开文件
参数有两个:参数a为文件路径
参数b问文件打开模式
这里面对参数b进行解释:
“r” --=>只读,在文件的开头开始
“r+”--=>读写,在文件的卡头开始
“w”--=>只写,打开文件并清空文件内容,如果不存在文件则创建
“w+”--=>读/写,打开文件并清空文件内容,如果不存在文件则创建
“a”--=>追加,打开文件并向文件末端进行写操作,如果文件不存在则创建新文件
“a+”--=>读/追加,向文件末端写内容,并保持文件
“x”--=>只写 创建文件,如果文件存在则返回false
“x+”--=>读/写。创建文件 如果文件已存在,则返回false和一个错误
注释*:如果fopen()无法打开指定的文件则发挥0(false)
例子1:$file=fopen(“D:/abc.txt”,”r”);
例子2:$file=fopen(“D:/abc.txt”,”r”) or exit(“unable to open file!”);
注:此例子如果文件无法打开则弹出消息
23.feof($file)用来检索是否已经达到文件末端
注释:在权限为:w, a, x, 时是无法打开文件的

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.
