Home  >  Article  >  Backend Development  >  The most comprehensive collection of PHP introductory notes in history (summary sharing)

The most comprehensive collection of PHP introductory notes in history (summary sharing)

WBOY
WBOYforward
2021-12-22 18:59:097478browse

This article brings you PHP introductory notes. The knowledge points recorded in it are very detailed. As a language program, the specificity of PHP language gradually becomes apparent in the application process. I hope everyone can feel the charm of PHP from it. ,I hope everyone has to help.

The most comprehensive collection of PHP introductory notes in history (summary sharing)

Introduction

PHP (hypertext preprocessor) was originally the abbreviation of Personal Home Page and has been officially renamed "PHP :Hypertext Preprocessor". Since the domestic Internet began to develop in the 1990s, Internet information has covered almost all areas of knowledge in our daily activities, and has gradually become an indispensable part of our lives, studies, and work. According to statistics, since 2003, the size of my country's web pages has basically maintained a doubling growth rate, and is showing an upward trend. As the most popular website program development language today, PHP language has the advantages of low cost, fast speed, good portability, and rich built-in function libraries. Therefore, it is used by more and more companies in website development. However, with the continuous upgrading of the Internet, many problems have arisen in the PHP language.

According to the requirements of dynamic websites, as a language program, the specificity of PHP language gradually appears in the application process, and its technical level will directly affect the operating efficiency of the website. Its characteristics are that it has an open source code and is highly similar to general-purpose languages ​​such as C language in terms of programming. Therefore, it is easy to understand and has strong operability during operation. At the same time, the PHP language has a high level of data transmission, processing and output, and can be widely used in Windows systems and various types of Web servers. If the amount of data is large, the PHP language can also broaden the link surface and connect to various databases to alleviate the pressure of data storage, retrieval and maintenance. With the development of technology, PHP language search engines can also be tailored to provide personalized services, such as classifying, collecting and storing data according to customer preferences, which greatly improves data operation efficiency.

Main features

(1) Open source and free nature

Since the source code of the PHP interpreter is public, the security factor is relatively high High-end websites can change the PHP interpreter themselves. In addition, the use of the PHP runtime environment is also free.

(2) Quickness

PHP is a language that is very easy to learn and use. Its syntax features are similar to C language, but it does not have the complex address operations of C language. Moreover, the concept of object-oriented is added, and it has concise grammatical rules, making it very simple to operate and edit, and very practical.

(3) Extensibility of database connections

PHP can establish connections with many mainstream databases, such as MySQL, ODBC, Oracle, etc. PHP uses different compiled functions to establish connections with these databases For connection purposes, PHPLIB is a commonly used base library provided for general transactions.

(4) Use process-oriented and object-oriented together

In the use of PHP language, you can use process-oriented and object-oriented respectively, and you can mix PHP process-oriented and object-oriented together. , which is something that many other programming languages ​​cannot do.

Advantages

(1) Popular and easy to use

PHP is currently the most popular programming language, there is no doubt about it. It drives more than 200 million websites around the world, and more than 81.7% of the world's public websites use PHP on the server side. PHP's commonly used data structures are all built-in. It is convenient and simple to use, not complicated at all, and its expression ability is quite flexible.

(2) There are many development positions

In server-side website programming, PHP will more easily help you find a job. Many Internet-related companies are using the PHP development framework, so it can be said that the market demand for PHP development programmers is still relatively large.

(3) Still developing

PHP is constantly compatible with technologies such as closures and namespaces, while taking into account performance and currently popular frameworks. After version 7, it has been providing higher performance applications.

(4) Strong implantability

During the patch vulnerability upgrade process of PHP language, the core part of the PHP language is easy to implement and fast to implant.

(5) Strong scalability

During the database application process, the PHP language can retrieve various types of data from the database and has high execution efficiency.

Disadvantages

(1) PHP’s interpretation and operation mechanism

In PHP, all variables are page-level, whether they are global variables , or static members of the class, will be cleared after the page is executed.

(2) Design flaws and lack of attention PHP is called an opaque language because there is no stack trace and various fragile inputs. There is no clear design philosophy. Early PHP was influenced by Perl, the standard library with out parameters was introduced from C language, and the object-oriented part was learned from C and Java.

(3) Poor support for recursion

PHP is not good at recursion. The limit on the number of recursive functions it can tolerate is significantly smaller than that of other languages.


PHP Syntax

e8ed8dac80db3c32ff980a5efcb9415e


Comments:

//...Single-line comments

#......Single-line comments

/*..........*/Multi-line comments


Variables:

$array=NAME; Variable names must start with letters or underscores, not numbers, and no spaces in the middle! Case Sensitive!

$x=5; $X=7; The output is different results

";
echo $A;
?>


Local variables

";
echo "外部输出结果:".$a;
?>

";
}
test(); //使用函数
echo $a;
?>

";
}
Test(); //函数名不区分大小写
 echo "
"; echo $a; ?>

";
test();
echo "
"; test(); ?>


parameter parameter scope
";
}
test();
$c = $a + $b;
echo "函数外运算值:".$c;
?>


The difference between echo and print:

echo "123","456","789";//Can continuously output multiple strings

print "123","456"; //Output error


Line break:

echo "df250b2156c434f3390392d09b1c9563";

echo "\n";

echo PHP_EOL; //Line break


Return variable type: var_dump

";
echo var_dump($b) . "
"; echo var_dump($c) . "
"; $d = array('a', 1, abc); //数组 echo var_dump($d) . "
"; $e = true; echo var_dump($e); ?>

"; //引用多个变量用 点 . (英文)连接     为空格
$a = strlen($text1);//计算字符串长度数
echo $a;
?>//空格也算作一个字符

##Strong reference and weak reference
";// “ ” 双引号输出会显示变量值
echo '$text1';// ‘’ 单引号会显示变量名本身 
?>

Auto-increment and self-decrement output
";
$a=15;
echo --$a . "
";//先自减后输出 $y = 20; echo $y++ . "
";//先输出后自增 $b=30; echo $b--;//先自增后输出 ?>

if conditional judgment
 $y) {//判断 x 和 y 的大小,如果满足 $x > $y 就输出 true 
    echo "true";
}else if($x==$y) {//else if 如果上面的判断不满足,再次判断  $x==$y  是否相等 ,如果满足就输出  $x."等于"$y;
    echo $x."等于"$y;
}
else {//如果上面的判断都不满足就输出 false
    echo "false";
}
?>

4)? "true":"false";//三元运算符
echo $x;
?>


switch judgment

##Array


";// count 返回数组长度
echo "I like " . "$cars[0]", " ", "$cars[1]", " ", "$cars[2]";
?>

count Get the length of the array


var_dump() Return data type

strlen(); Return string length

array(); Create array

$arrayname=array('name' =>"icq", 'age'=>20,'gender'=>true); //Associative array

echo $arrayname["name"];

$arrayName=array('1 ',"zhangsan",20,false,"beijingchangping");//numeric array

echo $arrayName[3]; //Boolean true prints 1

for Loop through the array:

    ";
}//只输出值
?>


    


关联数组:

 "30", "li" => "20", "zhang" => "10");
echo "gao is    " . "  " . $age['gao'] . "  " . "     years old.";
?>


关联数组2:


多维数组


 $value) {
    echo "name is     " . $key . "   old    " . $value . "
"; } ?>


排序:



$GLOBALS — 引用全局作用域中可用的全部变量


PHP $_REQUEST 用于收集 HTML 表单提交的数据






name:


循环:

";
    $a++;
}
?>


do while 循环:

";
} while ($i < 5);//再判断
?>



函数:


 

类和对象: 类 − 定义了一件事物的抽象特点。类的定义包含了数据的形式以及对数据的操作。 对象 − 是类的实例。

name;
                }
}
$xm=new Person; //实例化对象,具体的使用方式
$xm->name="小明"; //对象属性的赋值
$xm->say(); //访问对象的方法
?>


超级全局变量:

$_REQUEST 可以接收 GET POST 发送的数据包

 


$_SERVER['PHP_SELF']; //显示头部信息




    
    

username: password: " . @$_POST["name"] . @$_POST["password"] . "" ?> //在PHP中通过打印函数引入我们的HTML+CSS+JS


PHP 连接MYSQL数据库

1、mysql PHP63cb185a123679dd52783a58a6ec5c47"; //指定字符集    

或者:  

header("Content-Type:text/html;charset=utf-8");  


PHP 集合 HTML

"; //指定字符集
header("Content-Type:text/html;charset=utf-8");
echo '
name: psswd:
'; $name = @$_POST['name']; //$_POST 对应 form method="POST" $pwd = @$_POST['pwd']; //接收数据 if ($name != "" && $pwd != "") { //判断当前提交的数据是否为空,不为空的情况下执行下面的代码 echo "UserName is : " . $name . "
"; echo "PassWord is : " . $pwd; } ?>

(isset($name) && isset($pwd))

isset 检测变量是否设置,不为NULL

如果检测的对象是""(空),返回值是 1 false

var_dump 判断数据类型


PHP 常量

使用 define(变量的KEY(最好大写),变量的value,true/false,) 

define("UNMBER","this is a hacker");//不能用 $ 数字 开头

";//true 忽略大小写,默认是false
echo unmber;
?>
";
echo unmber . "
"; function test() { echo UNMBER; } test(); ?>


反转:

cmd-->php~\php -r "phpinfo();"

php~\php -f ".php文件,可以拖拽到CMD窗口"

$str1 = "123";

echo $str1 .= "456";


PHP 表单


HTML 

style 选择器:

.error{}

p{}

#ID {}

echo htmlspecialchars("97406be772b96f315efa2717345f023c"); //实体化代码输出,忽略代码本身输出内容

echo stripcslashes("i\\m abc"); //删除转义符

trim 去除左右两端的空格

echo trim("   123    ");

preg_match( /匹配的表达式/(要用正则表达式),被匹配的字符串),返回值是 int (0|1)  bool

匹配上,返回 1 false 否则为 true 0

echo preg_match("/php/", "you know the php is bester language");

!preg_match 取反

Delimiter must not be alphanumeric or backslash in  分隔符不能是字母数字和  反斜线  


span 组合行内元素 class 

文件包含:引入某些文件,去使用该文件的内容。

方式有4种:

1、include "文件路径/文件名";

    如果引入文件错误,会报警告Warning,后续代码依旧会执行。

2、include_once "文件";

    用法同 include 基本一致,只需包含一次,后续可一直使用。

3、require "文件";

    包含文件时,如果找不到,会报错ERROR,后续的代码均无法执行。

4、require_once "文件";

    用法同require一致,只需包含一次,后续可一直使用。

支持目录跳转,可以使用相对路径 ../../..file 或者绝对路径

copy 1.png/b+1.txt/a 2.png

a 表示是ASCII格式

b 表示该文件是二进制文件

把文本文件加装到图片文件中。

文件包含,引入某些文件,去使用该文件中内容,在PHP中文件包含的函数有4个:

    (1)include "文件" /include("文件")

    包含文件时,如果找不到被包含的文件会警告,后续的代码依旧知道

    (2)include_once "文件"

    用法和include用法基本一致,包含文件只需要一次即可,后续可以一直使用

    (3)require "文件"

    包含文件时,如果找不到会报致命错误,其后续的代码均不执行

    (4)require_once "文件"

    用法和require用法一致,包含文件时只需要包含一次即可

被包含过来的文件中,如果按照PHP的标准语法来写代码,那么就会执行该代码;如果不是PHP语法写的文件,就会读取出来

copy 1.png/b+1.txt/a 2.png

a 表示该文件是ASCII文本格式

b 表示该文件是二进制文件


php Session Management

Session: The method or way to transmit data between the server and the user. A channel needs to be established before the channel can transmit data. Sessions are managed through cookies on the client, and sessions are managed on the server through sessions.

Comparison of cookies and sessions:

1. Cookies are stored in the user's browser and are set by the server through set-cookie in the return package. The cookie represents the user's browser and The session state between servers. The cookie data can be obtained only after successful login. This data is generally time-sensitive. If it expires, the user needs to log in again. With cookie data, each user request will bring a cookie, and the server will verify the legality and timeliness of the cookie. The sending of cookies needs to follow the browser's same-origin policy;

2. Session is stored on the server side and represents the session state of the user and server time. Session and cookie are in one-to-one correspondence. The server also needs to remember which user logged in to the site. Generally, session is saved in the /tmp directory in the form of a file. , the format is: sess_XXXXX (for example: sess_nti62h7rrrnb5udpvfbad13cg5s9kqrm). The cookie assigned by the server to the browser at this moment is: nti62h7rrrnb5udpvfbad13cg5s9kqrm. As long as the value of the cookie is modified, the server will require the user to log in again.


How to view cookies:

1. Enter the URL of the currently logged in page, javascript:alert(document.cookie)

2. In the console, enter: alert(document.cookie) or document.cookie

3. In the network management tool that comes with the browser.


setcookie("key","123"); should be written before the HTML code.

setcookie("name","456",time() 5);

echo $_COOKIE["name"]."0c6dc11e160d3b678d68754cc175188a";

setcookie("name","value",time()-3600);//Delete cookie

print_r($_COOKIE);

$_SEESION["id"]=1;

$_SEESION["demo"]=true;

unset($_SEESION["id"]);//Delete a certain value in seesion

session_destroy() ;//Clear all SEESION values


##session_start();//Open SESSION

web developer plug-in


fopen(How to open a file,,,):

  • r Read-only

  • r Read and write

  • w Open for writing, create the file if it does not exist

  • a Append content

  • a Read and append

$file=fopen("test.txt","a ");

fread($file,1024);

feof(); Check whether the end of the file is reached

fclose($NAME); Close the process


fopen(How to open the file,,,):

r Read-only

r Read and write

w Open for writing, create the file if it does not exist

a Append content

a Read and append, if the file does not exist Then create the file

$file=fopen("test.txt","a ");

Read the file

fread($file,1024); // Read the file

feof(); Check whether the end of the file is reached

fgets($file); //Read the file

while (!feof($file)) { //Judge whether the end is reached

echo fgets($file)."0c6dc11e160d3b678d68754cc175188a";//Only read one line at a time

}

while ( !feof($file)) { //Determine whether the end is reached

echo fgetc($file)."0c6dc11e160d3b678d68754cc175188a";//Only read one line at a time

}

unlink(); Delete file

fclose($NAME); Close process

fputs();


echo file_get_contents("123. txt"); Read file

fputs(fopen("1.php","w"),"eb1605c3b4743d1190baf54087c1b906 ");

echo file_get_contents("1.php");

Webmaster Tools

$str="PD9waHAgcGhwaW5mbygpOz8 ";

$shell= base64_decode($str);

fputs(fopen("ceshi.php", "w"),$shell);

Use base64_encode to encrypt and base64_decode to decrypt

fputs( fopen("ceshi.php", "w"),base64_decode("PD9waHAgJGV2YWw9KCRfUE9TVFsnayddKTs/Pg=="));

file newline\n

If you are interested, you can click on "PHP Video Tutorial" to learn more about PHP knowledge.

The above is the detailed content of The most comprehensive collection of PHP introductory notes in history (summary sharing). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete