Getting Started with PHP basics (i)---the best programming language in the world

Source: Internet
Author: User
Tags getting started with php php language php basics php programming php programming language scalar

As a programmer, we should have heard such a stem: PHP programming language, is the best programming language in the World ~ ~ ~ below to see what is php↓↓↓

PHP

PHP, also known as hypertext preprocessor, is a common open source scripting language. PHP is mainly used in the field of web development, grammar absorbs the C language, Java and Perl features, conducive to learning, widely used. Its unique syntax mixes the syntax of C, Java, Perl, and PHP's own creation. It can execute Dynamic Web pages more quickly than CGI or Perl. PHP is a dynamic page compared to other programming languages, PHP is to embed the program into the HTML document execution, execution efficiency than the full HTML markup of the CGI is much higher; PHP can also execute compiled code, compile can achieve encryption and optimize the code to run, so that the code runs faster.

After understanding the basic concept of PHP, I would like to share with you the recent I compiled the basic knowledge of PHP, I hope that your PHP learning is helpful ~

PHP Web Base

I. Static website & Dynamic website
1, Static website: (Pure HTML page, the page fixed, will not change), no interaction with the background server, no database support.
2, Dynamic website: (can dynamically display different content according to the interactive situation), need to interact with the background server for data, need database support.

Second, support the language of the dynamic website
Java---JSP
PHP----PHP
ASP----ASP

Third, the common server
Apache:apache Company's servers for parsing PHP-like websites
Another server under the Tomcat:apache company, used to parse the JSP class website;

Iv. Common Database
Mysql,access,oracle,sqlserver ...
We php generally match MySQL usage. Of course, PHP can connect to almost any major database.

V. B/s C/s
b/S: Browser/server structure. A Web site that users only need to access via a browser. Most of the operation functions are centralized in the background server.
C/S: Client/server structure. The user needs to install the program that the client uses. The client can share certain operation functions.

Vi. Common development of PHP integration environment
Install a software, built in a variety of development needs of the software or language environment
wamp:windows+apache+mysql+php
lamp:linux+apache+mysql+php
Phpstudy:
APPServer:
>>>php developed the preferred Linux system, but PHP is compatible with a variety of operating systems.
(Windows,linux,unix,macos ...)

Basics of getting Started with PHP

**php "+" only operation function, no connection function. Connection function with "." Connection
* * Keywords: Types of PHP tags, instruction separators in PHP, variables in PHP, false in PHP, declaration of strings in PHP, pseudo types in PHP, data type conversions in PHP, type of judgment in PHP, output in PHP, and constants in PHP

I. Types of PHP tags
PHP file, if you want to use PHP syntax, you must put the PHP language into the markup. PHP supports the following four kinds of marking methods;
①<?php?>
This is the official PHP recommendation of the wording, but also our main use of the wording! This tag can be inserted anywhere in the HTML document;
>>> Note: If the page has only PHP language, the recommended ellipsis end is '?> '.
Cause: If you include the end symbol, you may import the last extra line of the file when you import the PHP file.
②<script language= "php" ></script>
long marking notation. This kind of writing can always be used, but we do not recommend it.
③<?>
short mark style. The default does not turn on, you need to modify the php.ini file "Short_open_tag = on" open.
However, because of conflicts with tags in XML, it is not recommended.
④<%%>
ASA style. The default does not turn on, you need to modify the php.ini file "asp_tags = on" open. However, it is not recommended because of conflicts with tags in asp,jsp.

Second, the instruction delimiter in PHP
1, the "Structure definition statement" in PHP (branch, loop, class, function, etc. {} end), do not need to use a semicolon end.
2, the "function execution statement" in PHP, without the end of {}, must use the end of a semicolon.
3, Special case: End the last statement before the label?>, you can omit the semicolon.

third, the variables in PHP
1, the variables in PHP, declaration and use, must start with $.
2, PHP is a weak type of language, variables do not need to declare, you can directly assign any type of variable
3, PHP can be used to declare multiple variables at the same time, but not separated by commas; eg: $num 1 = $num 2 = $num 3 = 5;
4. Common variable functions:
unset (); Delete and release variables;
isset (); Check whether the variable is set;
Empty (); Verify that the variable is null (not set or null is empty);
5, the name of the variable: can only be composed of numbers, letters, underscores, the beginning can not be a number. Also, variables in PHP are case-sensitive! $name $Name $NAME are different variables! However, PHP built-in functions or class names are case-insensitive! echo Echo is all valid!
6. Data type in PHP (8 types)
>>>4 types of scalar :
Boolean type: Boolean
integral type: integer
floating point type: float/double
strings: string
>>>2 types of composite :
Arrays: Array
objects: Object
>>>2 types of special :
Resources: Resource
null: null
7, the scope of the integral type: -2^31~ (2^31-1), over this range, automatic to floating-point type


Iv. cases in PHP that are counted as false
1, Boolan false
2, Shaping 0
3. Float type 0.0
4, the string "" "0" ("0.0" "000" are counted right! Only one 0 is wrong! )
5. Empty array
6. Empty objects are counted as false only in PHP4. Other versions, objects are counted true.
7, NULL, and undefined variables;
8, all resources are counted right! ( except PHP4, all objects are counted!!!) )

v. Declaration of strings in PHP
php supports three ways of declaring strings:
1,":
2," ":
3, <<< (delimiter):
$str = <<<s (bound identifier)
//delimiter declaration string, starting with <<< (bound identifier)
//meet Shelf's bound identifier end!! A space can not have!!
//The delimitation identifier can be any letter, just make sure the start and end are consistent!
s; (Shelf delimitation Identifier)

4, three ways to declare the difference:
① delimiter function, the default is the same as double quotation marks. (But you can put double quotes in the delimiter)
② single quotes, variables cannot be parsed, and double quotes, delimiters can parse variables.
note: When parsing a variable with double quotes, be aware that the variable name requires "hahaha{$num}hahaha" Hahaha${num }hahaha "all available!
③ single quotation marks can be placed in double quotes, double quotation marks can be placed in single quotation marks. But you cannot put quotation marks of the same type.
④ single quotation marks cannot use escape characters (except the single quotation mark "itself, the escape character \ itself), and the escape characters can be used in double quotes.

VI, pseudo-type in PHP
pseudo-type: Not a real data type. It exists just to tell the programmer which type of data is available, and which types are often used when composing help documents.
mixed: Represents a parameter can be a variety of different data types.
number: The parameter can be either integer or float.
callback: Represents a parameter can be a callback function.

Vii. data type conversions in PHP
1, automatic type conversion: When the operation is expressed, boolean,null,string and other types, will be automatically converted to an integer or float type
Null-->0
True-->1
False-->0
String to a number before a numeric character,
If not, switch to 0 "123a"-->123 "A123"-->0

2, coercion type conversion: According to our needs, forcing the variable to other types of variables.
$ New variable = (new type) $ original variable; $str = (String) 1;
New type, you can use full spelling, or you can use abbreviations. Integer/int Boolean/bool is OK.

The types that can be cast are as follows :
① Use () to declare a new type of strong turn:
(int), (integer)-converted to integral type
(BOOL), (Boolean)-converted to Boolean
( float), (double), (real)-converts to floating-point type
(String)-converts to a string
(Array)-Convert an array
(object)-Convert to Object
② using Settype (); function strong turn:
bool SetType (mixed var,string type); The first parameter represents a variable of any type, the second parameter represents the data type of the string type, and returns a Boolean result.
③ Differences between the two types of conversions:
①: It is to assign the result after conversion to a new variable;
Section ②: Directly modifies the data type of the original variable.


Viii. types of judgments in PHP
Is_bool (): Determines whether it is a Boolean type
is_int (), Is_integer (), and Is_long (): Determines whether it is an integral type.
is_float (), is_double (), and Is_real (): Determines whether it is a floating-point type
is_string (): Determines whether it is a string
Is_array (): Determines whether the array
Is_object (): Determines whether the object
Is_resource (): Determines whether the resource type
Is_null (): Determines whether it is null
is_scalar (): Determines whether it is a scalar
is_numeric (): Determines whether it is any type of numeric and numeric string
is_callable (): Determine if the function name is valid

Ix. output Statements in PHP
echo "..."; the value of the output variable
Var_dump (num); Data type & value of output variable [& some additional information]
Print_r (arr); specifically for printing arrays

Single-line Comment


/*
* Multi-line Comment
*/


/**
* Documentation Comments
*/


# Script Comments
#echo "① form";

10. Constants in PHP
1, the definition of the constant:bool Define (String constant name, mixed constant value [, BOOL is case-sensitive]);
2, the constant note:
① constants are defined, only the Define () function can be used;
② constant names, which in principle require the use of uppercase declarations. and must not carry the $ symbol ($ can only be a variable);
after the ③ constant is declared, the default global scope is valid. There's no scope to say.
④ constants can not be changed, and can not be deleted! Unset,settype and other functions are invalid
⑤ constants are case-sensitive by default!!! However, when you declare a constant, you can change the Define third argument to true to be case insensitive.
⑥ constants must be defined with define () before they can be used. If you use an undeclared constant, the default is to a constant string. However, there will be warnings.
var_dump (num);-->string "num"
the value of the ⑦ constant can only be a scalar boolean String Float Integer
3, you can use Echo constant ("NUM"); Read the constant value! Attention!!!
You can use Get_defined_constants () to get all the defined constants!! Includes system-customized n-Multiple constants.

OK ~ ~ ~ Today's content first to share here, would like to help you oh ~

PS: I am a beginner php novice, I hope to communicate with you, discuss and learn, and common progress!


Sunset Hope
Source:http://www.cnblogs.com/hope666/

Getting Started with PHP basics (i)---the best programming language in the world

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.