此文写于20171005,我对php的入门理解,可能有偏差,后续还要调整,优化记忆和理解。

reference http://php.net/manual/en/langref.php

入门例子:

  1. 来自神秘命令行的php简易服务器
php -S localhost:8000

PHP ${version} Development Server started at Thu Oct  5 15:58:19 2017
Listening on http://localhost:8000
Document root is /Users/${username}/testdir/php

2.php header破除同源限制,实现便捷调试

<?php
/*注意顺序哦,header要在echo之前进行调用*/
header('Content-Type:text/html;charset=utf-8');
header('Access-Control-Allow-Origin:*');

echo "<html>";
echo "<h1>this is for test</h1>";
echo "</html>";
?>

3.要想快速入门就是写实际可以运行的代码 基本要掌握这几个字

$作为变量的代表
php中有两种输出的方法
echo
print

4.最重要的就是交互式解释器 我认为使用交互式解释器是学习一门编程语言最接地气的方法了

php -a可以开启交互式解释器
-a             Run as interactive shell

5.查看类型

用来查看变量类型
gettype()
和
var_dump()

基本语法(果然天下的语言都是相似的) php代码写在标签之内

which tell PHP to start and stop interpreting the code between them

types

boolean

True
False

integer

float

string

variables

$开头后面加上名字

Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive.

control structures

if

<?php
if (condition){
}
?>

while and do…while

<?php
while (condition){
  statement
}
?>
<?php
$i = 0;
do {
    echo $i;
} while ($i > 0);
?>

for

<?php
for ($i = 1; $i <= 10; $i++) {
    echo $i;
}
?>

Predefined Variables

这里相当于是php的特色吧,一般的语言怎么才不会有这么多的内置变量呢,主要是这些变量为web开发提供便捷,也就是说php是专门为web而搞的。

These superglobal variables are
$GLOBALS
$_SERVER
$_GET
$_POST
$_FILE
$_COOKIE
$_SESSION
$_REQUEST
$_ENV

<?php
var_dump($_SERVER)
?>