PHP tag style, coding standards

image.png

PHP tag style
PHP supports a total of four radiolabeled style

<?php 
    echo "这是XML风格的标记"; 
?>

Script style

<script language="php"> echo '这是脚本风格的标记'; </script>

Short style

<? echo '这是简短风格的标记'; ?>

ASP style

<% 
echo '这是ASP风格的标记'; 
%>

php.ini file

The short_open_tag and asp_tags
are set to ON, you can restart the Apache server

PHP coding standards
What is the coding standard
PHP writing rules
PHP naming rules

Indent
braces {}
keyword, parentheses, functions, operators,

PHP naming rules

Class name
in uppercase letters as a separate word, the other letters are lowercase
initials uppercase
Do not use the underscore ( '_')

Class Attribute Name
Attribute names should be the character "m" is prefixed

Method Name
Is
(determination), Get (get), Set (set)

The method parameter is named
the first character lowercase

function EchoWord($firstWord,$secondWord){
…
}

Variable naming
all the letters are lowercase
use '_' as each word boundaries

Reference variable
references to variables with the "r" prefix

Global variables
Global variables should be prefixed with "g"

global = $gTest

Constant / Global Constants

Constant / global constants, should all capital letters, with between words '_' to separate

Static variables
Static variables should be prefixed with "s"

Function naming
all the names are lowercase letters, use more than one word, "_" to separate

PHP Notes
PHP supports three styles of program comments

C++风格的单行注释(//)
C风格的多行注释(/*…*/)
Shell风格的注释(#)

PHP constants
declaring and using constants
predefined constants

Constants can be understood as the value of the same amount
a constant consists of letters, underscores and numbers, but the numbers can not appear as the first letter of the
define () function to define constants

image.png

Declaring and using constants

mixed constant(string const_name)
bool defined(string constant_name);

Predefined Constants

image.png

PHP variables

Declare variables
variable assignment
variable scope
variable variable

$变量名称=变量的值

Variable assignment three ways
(1) direct assignment
(2) assignment by value
(3) assigned by reference

Variable Scope
three kinds of variable scope
of local variables, global variables and static variables

image.png

Variable Variable

Declare variable variable method is before the variable name with two "$" symbol

The syntax for declaring a variable variable as follows:

$$可变变量名称=可变变量的值

PHP Overview

PHP is a dynamic interactive site to create a powerful server-side scripting language

PHP is free, and is widely used

PHP syntax is very similar to Perl and C. PHP is often with Apache (web server) used together. But it also supports ISAPI, and can run on Windows, Microsoft IIS platform

What is MySQL?

MySQL is a database server
MySQL supports standard SQL
MySQL compiles on many platforms
MySQL free download

image.png

image.png

image.png

strlen () function
strlen () function is used to calculate the length of the string

the strpos () function
the strpos () function is used in a string or a character string retrieval character

PHP 运算符-算数运算符
PHP 运算符-赋值运算符
PHP 运算符-比较运算符
PHP 运算符-逻辑运算符

PHP的数据类型
Boolean型
integer型
浮点型
字符串型
复合数据类型

伪类型

mixed
number
void
callback

bool isset检测有没有被赋值
void unset销毁指定的变量

is_array()、is_bool()、is_float()、is_integer()、is_null()、is_numeric()、is_object()、is_resource()、is_scalar() 和 is_string()

bool empty
bool is_null

PHP的运算符包括算术运算符、字符串运算符、赋值运算符、位运算符、逻辑运算符、比较运算符、递增或递减运算符、错误控制运算符等。

算术运算符

image.png

赋值运算符

image.png

位运算符

image.png

逻辑运算符

image.png

比较运算符

image.png

运算符的优先顺序

image.png

PHP的数据类型

标量数据类型
复合数据类型
特殊数据类型
转换数据类型
检测数据类型

PHP一共支持8种原始类型:

4种标量类型
boolean(布尔型)
integer(整型)
float/double(浮点型)
string(字符串型)

两种复合类型
array(数组)
object(对象)

两种特殊类型
resource(资源)
NULL

标量数据类型

image.png

Complex data types - Array

$array = ('value1',' value2 '……)
或
$array[key] = 'value' 或 $array = array(key1 => value1, key2 => value2……)

Complex data type Object -

Special Data Types

image.png

Converting Data Types

image.png

settype () function

bool settype ( mixed var, string type )

Detection data type

image.png

 

Guess you like

Origin www.cnblogs.com/daofaziran/p/11571909.html