Chapter Three Basics of PHP
(3.1--3.5)
3.1 Embed PHP code in a Web page
Default syntax: <?php?>
Short tags: <??> or <?= "";? >--Not recommended
Script: <script language= "PHP" ></script>
ASP style: <%%>
3.2 Adding comments to the Code
Single-line C + + syntax://
Shell syntax: #
Multi-line C syntax:/*
This
That
*/
3.3 outputting data to the browser
Print (): 1.print ()
2.print ""
Echo (): 1.echo ()
2.echo ""
printf (): Interger printf (string format [, mixed args])
printf () facilitates the output of mixed products consisting of static text and dynamic information stored in one or more variables
printf ("Bar inventory:%d bottles of tonic water." 100)//output: Bar inventory:100 bottles of tonic water.
sprintf (): String sprintf (String format[, mixed arguments])
The sprint () function functions the same as printf (), but it assigns the output to a string rather than directly to the browser
$cost = sprintf ("$%.2f", 43.2); $cost = $43.20
P.S Common Type indicators
%b the argument as an integer, displayed as a binary number
%c considers the argument to be an integer that is displayed as the corresponding ASCII character
%d considers the argument to be an integer, displayed as a signed decimal number
%f the parameter as a floating-point number, displayed as a floating-point number
%o The argument is considered an integer, which is displayed as an octal number
%s considers the argument to be a string, displayed as a string
%u considers the parameter to be an integer and is displayed as an unsigned decimal number
%x considers the argument to be an integer, which is displayed as a lowercase hexadecimal number
%x considers the argument to be an integer, which is shown in uppercase hexadecimal number
3.4 Data types supported by PHP
A data type (datatype) is a generic term for data with a set of identical attributes.
Common types of data include:
Boolean: Returns True or false, case insensitive. Available 0 for false, non-0 value indicates true
Shaping: Decimal, octal, hex
Floating point: Also known as single-precision, double-precision, or real-numbers can specify numbers that contain fractional parts
String: In short, a string is a sequential sequence of characters, usually defined in single or double quotation marks
Conformance data types include:
Array: Two-dimensional array, multidimensional array
Object: The object must be displayed for declaration. The behavior of declaring object properties is done in class.
In-depth objects:
classAppliance {Private $_power; functionSetpower ($status){ $this->_power =$status; }}...$blender=NewAppliance;/*The class definition creates some properties and functions related to the data structure (appliance here), and appliance has only one property power, which can be modified with setpower (). A class definition is a template that cannot be manipulated by itself, and objects are created based on this template. This is done with the new keyword. So the last line creates an object of class appliance, called Blender, so that you can use Setpower () to set the power properties of the Blender object: $blender->setpower ("on")*/
Use type casting to implement conversions between data types:
P.S Type conversion operator
Conversion operator to
Arrays (Array)
(bool) or (Boolean) Boolean value
(int) or (integer) integer value
(object) objects
(real) or (double) or (float) floating-point number
(String) string
Type auto-conversion: PHP is very loosely defined for type definitions, and sometimes the variables are automatically converted to integer types based on the environment in which they are referenced.
Types-related functions:
Get Type: GetType () Form: String GetType (mixed Var)
Conversion type: Settype () Form: Boolean settype (mixed var,string type)
Type identifier function: Form: Boolean is_name (mixed Var)
3.5 identifiers
A valid identifier must meet the following properties:
Start with a letter or underscore
Can only consist of letters, numbers, underscore characters, and other ASCII characters from 127~255
Case sensitive
Any length
The identifier name cannot be the same as any PHP pre-defined keyword.
PHP and MySQL Program design "Fourth Edition" chapter Three essays--(1)