Php BASICS (1)

Source: Internet
Author: User

Php supports four tag styles:
1)
<? Php
Echo "this is an xml style Mark"; // recommended
?>
2)
<Script language = "php">
Echo "this is a script style Mark ";
</Script>
3)
<? Echo "Short STYLE tag";?>
4)
<%
Echo "this is an ASP-style Mark ";
%>
/*
To use the short style and asp style, you need to configure it in php. ini, and then set short_open_tag and asp_tags to ON
*/


Php supports three Annotations:
// Single line comment in c ++ Style
/**/C-style multi-line comment
# Shell-style comments
/*
Do not show in single line comment?> Because the interpreter will think that the php script is over and then execute the following content
*/


Data Types in php:
Php supports eight primitive types, including four scalar types (boolean, integer, float, string)
Two composite types: array and object
Two special types: resource, null


About boolean
Boolean has two values: true and false.
* In php, not only false is false, but 0 0.0 "0" "Only declares that all arrays without assignment are false.


About string
There are three methods to define a string: single quotation marks (recommended), double quotation marks, and delimiters.
Difference between single quotes and double quotes:
1) when using single quotes, you only need to escape single quotes, and use double quotes to escape "$" and other characters through \
2) using single quotes, the content will be output as is. Using double quotes, php will spend some time processing the conversion of strings and variable parsing.
Identifier:
$ S = <str
String content
Str; // there must be no space before it. It is no different from double quotation marks.


About integer
The integer number can be expressed in decimal, octal, and hexadecimal notation. If it is octal, add leading 0. If it is hexadecimal, add 0x.
If an invalid number (8, 9) appears in the octal, the subsequent number is ignored.
If the given value is beyond the maximum range expressed by the int type, it is processed as a float type. This is called integer overflow.


About float
The value of a floating point is only an approximate value. Do not compare it with a floating point, because the result is often inaccurate.


About null
Case Insensitive,
There are three situations where null values are assigned: variables that have not been assigned any value, are assigned null values, and are processed by the unset () function?
The function that determines whether it is null is is_null (), and the return value is of the boolean type.
From php4, unset () does not return values.


Forced type conversion:
(Boolean) to boolean
(String );
(Integer );
(Float );
(Array );
(Object );
* When converted to a boolean value, null, 0, and unassigned variables or arrays are converted to false, and others are true.
When converted to an integer, the values of the Boolean Type "false" and "true" are 0, and the decimal places of the floating point number are removed. If the numeric type starts with a number, it is truncated to a non-numeric bit. Otherwise, 0 is output.


You can also use the settype () function to complete type conversion,
Bool settype (mixed var, string type)
The var parameter is the specified variable. The type parameter is of the specified type and has seven optional values (boolean, float, integer, array, null, object, string)
The settype function converts the type of the original variable, while the forced type conversion only generates a temporary variable. The original variable type will not change.


Functions of the monitoring data type:
Is_bool () is_string () is_float ()/is_double () is_integer ()/is_int () is_null () is_array () is_object () is_numeric ()
Is_numeric () checks whether the variable is a number or a string composed of digits


Php constant:
Use the define () function to define constants:
Define (string constant_name, mixed value, case_insensitive)
Constant_name constant name
Constant value
Case_sensitive (optional) Specifies whether to be case sensitive. true indicates no sensitivity.
There are two methods to get the value of a constant: one is to get the value directly using the constant name, and the other is to use the constant () function.
Mixed constant (string const_name) // return the constant Value
To determine whether a constant has been defined, use the defined () function.
Bool defined (string constant_name)


Php predefined constants:
_ FILE _ php program FILE path
_ LINE _ row where the constant is located
PHP_VERSION
Name of the operating system in which PHP_ OS executes the php parser


Php variable:
In php, there is a reference value assignment. Different names are used to access the content of the same variable. When the value of one of the variables is changed, the other variable also changes and is represented by the & symbol.
$ I = "Hello ";
$ S = & $ I;
Variable Scope
A local variable defined in the function. Its scope is the function
Global variables are defined outside all functions, and their scope is the entire PHP file. However, they cannot be accessed in user-defined functions. If you want to use global variables in user-defined functions, use the global declaration
Static variables can retain the variable value after the function call ends.
For example:
<? Php
$ I = 'hello ';
Function fun (){
Global $ I;
Echo $ I; // output hello
}

?>


Variable:
A variable is a unique variable that allows you to dynamically change the name of a variable. The working principle is that the name of the variable is determined by the value of another variable, the implementation process is to add a dollar sign before the variable.
$ I = 'abc ';
$ Abc = 'hello ';
Echo $ I; // hello

Www.2cto.com
Php pre-defined variables:
$ _ SERVER ['server _ ADDR '] IP address of the SERVER on which the script is currently running
$ _ SERVER ['server _ name'] NAME of the SERVER host where the script is currently running
$ _ SERVER ['request _ method'] request method for accessing the page
$ _ SERVER ['remote _ ADDR '] browsing the user ip address on the current page
$ _ SERVER ['remote _ host'] is browsing the HOST name of the user on the current page
$ _ SERVER ['remote _ port'] PORT used by the user to connect to the SERVER


From the column of Youth China hang

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.