Basic knowledge of PHP (i)

Source: Internet
Author: User
Tags scalar

PHP (Hyper-text preprocessor) Definition:

PHP (Foreign name: Php:hertext Preprocessor, Chinese name: "Hypertext Preprocessor") is a common open-source scripting language. The grammar absorbs the C language, Java and Perl features, is conducive to learning, widely used, mainly for the field of web development. PHP's unique syntax mixes C,java,perl and PHP's self-created syntax. It can perform dynamic Web pages more quickly than CGI or Perl. PHP is a dynamic web page compared to other programming languages, PHP is to embed the program into the HTML (Standard Universal Markup Language) in the document to execute, the execution efficiency than the full HTML markup of the CGI is much higher; PHP can also execute the post-compilation code, After compiling, you can achieve encryption and optimize code execution, making your code run faster.

1, the use of PHP:

PHP can generate dynamic page content.

PHP can create, open, read, write, delete, and close files on the server.

PHP can accept form data.

PHP can send and retrieve cookies.

PHP can add, delete, and modify data in the database.

PHP can restrict users from accessing certain pages in a webpage.

PHP is capable of encrypting data.

2. php Files:

php file ends with. php

• Can be used in short label style

Note: You must modify an entry by php.ini this configuration file:

Short_open_tag = On

Remember that you must restart your service after you modify the configuration file

• Note that the PHP code must end with a semicolon to end the vulgar computer. I'm done.

• Keywords-output

"Echo"

3. Variables:

A variable is a quantity that can be changed.

A variable is a box that is designed to store something that can change during the execution of a program and must start with $ in PHP.

Naming conventions:

1, starting with $, you can follow the English characters.

2, strictly case-sensitive.

3. Do not start with numbers and special characters.

4, it can be used in Chinese, but it is recommended not to use.

5. The underscore does not belong to special characters, so you can start with an underscore.

6, the number can be sandwiched between the middle or the end.

7, the variable name should have meaning.

Naming rules:

The name must make sense. No, come on. $ A, $b, $c

Follow the hump naming method or variable declaration when you add a space between the equals sign.

The operation of the variable:

1. Assigning Values to variables =

2. Output variable Echo

3, judge whether a variable exists isset ();

4, destroy the variable unset ();

4, single quote double quotes:

• Single quotes cannot parse variables, double quotation marks can parse variables.

• Double quotation marks perform the translated characters, and single quotes do not translate \n,\r,\t,\.

• He performs translations \ \ and \ '.

• You can use single quotes without double quotes, why? Because the efficiency of single quotation marks is faster than double quotation mark efficiency.

• If it is a string and a variable, use the. to connect.

• Insert a single quotation mark inside the double quotation mark, insert the variable inside the single quotation mark, the variable will parse "' $name '" ' Zhang San '.

• If you insert a variable inside a double quotation mark, add a space and a dot after it.

Otherwise the system will think that you are one, to be wrapped up without braces.

5. Data type:

Scalar:

Shaping: 1, 2, is an integer.

Float type: 1.2, 2.4, is a decimal.

Boolean type: True,false, True and false. Boolean

Strings: As long as you enclose them in quotation marks.

  

1 <? PHP 2     $name = ' John Doe ';3     $a = ' abc '; 4     $x = "123"; 5 6 ?>

The quotes inside the John Doe, abc,123, are all strings.

Mixed type:

Arrays: Array

1 <? PHP 2    $arr = [1,2,3,4, ' AA ', ' Zhang San ']; 3 ?>

Objects: Object

Special types:

Null: null

Resources: Resource, the resource is the picture on our computer, Avi,rvmb,mp3, the network request is the resource type.

6. Data type conversion:

1<?PHP2    $xx= ' 123.ABC ';3    $CC= 123.123;4    $QQ= 12;5    $null=NULL;6    7    Echo GetType($xx);8    Echo' <br/> ';9    Echo GetType($CC);Ten    Echo' <br/> '; One    Echo GetType($QQ); A    Echo' <br/> '; -    Echo GetType(intval($xx)); -    Echo' <br/> '; the    Echo GetType(Boolval ($xx)); -    Echo' <br/> '; -    Echo GetType(Strval($QQ)); -    Echo' <br/> '; +    Echo Var_dump(intval($CC)); -    Echo' <br/> '; +    Echo Var_dump(Floatval($xx)); A    Echo' <br/> '; at    Echo var-dump (intval($null)); -?> -    

  

• Forced type conversions:

Intval: Convert to reshape.

Floatval: Convert to floating point type;

Boolval: Convert to Boolean;

Strval: Converting to String type

• Forced Type Conversions Summary:

1, empty conversion to shaping will be 0;

2, the empty conversion to floating-point type into floating-point type 0;

3, empty conversion to a string will become an empty string ' tip: The middle cannot have any characters including spaces;

4, shaping if there is a string, the string will be removed to keep the previous number;

5. If there is a string after the floating-point type, the string is removed and the preceding number includes the decimal point;

• Determine common functions for data types:

Is_array (); Array

Is_string (); String

Is_bool (); Boolean

Is_float (); Floating point

Is_object (); Object

Is_int (); Plastic

Is_numeric (); Numerical

Is_rescource (); Resources

Is_ull (); Empty

Is_scalar (); Scalar

GetType (); Get type only

VAR_DUMP9); Output value also has type

    

Basic knowledge of PHP (i)

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.