Php basics (1) --- The best programming language in the world, php ---

Source: Internet
Author: User
Tags constant definition php basics php programming language

Php basics (1) --- The best programming language in the world, php ---

As a programmer, we should have heard of such a stem: PHP programming language, the best programming language in the world ~~~ Next, let's take a look at what is PHP?

 

PHP

PHP, also known as Hypertext Preprocessor, is a common open source scripting language. PHP is mainly applicable to the Web development field. The syntax absorbs the features of C language, Java and Perl, which is conducive to learning and widely used. Its unique syntax is a mix of C, Java, Perl, and PHP-created syntaxes. It can execute dynamic web pages more quickly than CGI or Perl. Compared with other programming languages, PHP embeds programs into HTML documents for execution. The execution efficiency is much higher than the CGI that generates HTML tags completely; PHP can also execute the compiled code, which can encrypt and optimize code execution to make code run faster.

 

After learning about the basic concepts of PHP, I will share with you the basic PHP knowledge I have recently compiled and hope to help you learn PHP ~

 

 

 

PHP web page Basics

I. Static websites & Dynamic websites
1. Static Website: (pure HTML page, fixed page, no changes), no interaction with the background server, no database support.
2. Dynamic websites: (different content can be dynamically displayed based on the interaction Situation). Data Interaction with the backend server is required, and database support is required.

2. Languages supporting dynamic websites
Java --- JSP
PHP----PHP
Asp ---- asp

Iii. Common servers
Apache: an Apache server used to parse PHP websites
Tomcat: Another Apache server used to parse JSP websites;

4. Common databases
Mysql, Access, Oracle, SQLServer ......
We usually use PHP to match MySQL. Of course, PHP can connect to almost all mainstream databases.

V. B/S C/S
B/S: Browser/Server structure. A website that you can access through a browser. Most of the operations are concentrated on backend servers.
C/S: Client/Server structure. You need to install the program used by the client. The client can share certain operation functions.

6. Common PHP Integrated Development Environments
Install a software with multiple built-in software or language environments required for development
Wamp: windows + Apache + mysql + PHP
Lamp: Linux + Apache + mysql + PHP
PHPStudy:
APPServer:
>>> The preferred Linux System for PHP development, but PHP is friendly and compatible with various operating systems.
(Windows, Linux, Unix, MacOS ......)

 

PHP Basics

** In PHP, "+" only has the computing function and no connection function. Connect "."
** Keywords: PHP tag type, command Separator in PHP, variables in PHP, false in PHP, declaration of strings in PHP, pseudo type in PHP, data type conversion in PHP, and determination in PHP type, output statement in PHP, constant in PHP

I. PHP tag types
In the PHP file, if you want to use the php syntax, you must put the PHP language in the tag. PHP supports the following four marking methods;
① <? Php?>
This is the official PHP recommendation and is also the main method we use! This label can be inserted to any location of the HTML document;
>>> Note: If the page contains only the PHP language, we recommend that you omit the end representation '?> '.
Cause: if the end symbol is included, the excess line break at the end of the file may be imported into the PHP file when you import the file.
② <Script language = "php"> </script>
Long mark writing method. This method can always be used, but we do not recommend it.
③ <? ?>
Short tag style. It is disabled by default. You need to modify "short_open_tag = On" in the php. ini file to open it.
However, it is not recommended because it conflicts with the tag in XML.
④ <%>
ASA style. It is disabled by default. You need to modify "asp_tags = On" in the php. ini file to open it. However, it is not recommended because it conflicts with the tags in ASP and JSP.

Ii. Command Separator in PHP
1. in PHP, the "Schema Definition Statement" (end of branch, loop, class, function, etc. {}) does not need to end with a semicolon.
2. The "function execution statement" in PHP does not end with {}. It must end with a semicolon.
3. Special Case: end tag?> The last statement before. You can omit the semicolon.

3. Variables in PHP
1. Declaration and use of variables in PHP must start with $.
2. PHP is a weak type language. variables do not need to be declared. You can directly assign any type to the variables.
3. Multiple variables can be declared simultaneously using connections in PHP, but cannot be separated by commas. eg: $ num1 = $ num2 = $ num3 = 5;
4. Common variable functions:
Unset (); Delete and release variables;
Isset (); checks whether variables are set;
Empty (); checks whether the variable is null (not set or if the value is null );
5. variable naming: a variable can only contain numbers, letters, and underscores. It cannot start with a number. In addition, 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 valid!
6. Data Types in PHP (8 types)
>>>Four scalar types:
Boolean: Boolean
Integer: Integer
Float Type: Float/Double
String: String
>>>Two composite types:
Array: Array
Object
>>>Two special types:
Resource: Resource
Null: null
7. Integer Range:-2 ^ 31 ~ (2 ^ 31-1), beyond this range, it is automatically converted to floating point


Iv. false in PHP
1. Boolan false
2. integer 0
3. Floating Point 0.0
4. String "" 0"("0.0" "000" is correct! Only one 0 Error !)
5. Empty Array
6. null objects are counted as false only in PHP4. For other versions, the object is true.
7. null monk undefined variables;
8. All resources are correct! (All objects except PHP4 are correct !!!)

V. Declaration of strings in PHP
PHP supports three methods to declare strings:
1 ,'':
2 ,"":
3. <(delimiter ):
$ Str = <s (delimiter)
// Declare the string by using the delimiters <(delimiter)
// The End Of The demarcation identifier of the top lattice !! No space is allowed !!
// The delimiter can be any letter. You only need to ensure that the start and end are consistent!
S; (identification of the top grid)

4. Differences between the three declaration methods:
① The delimiter function, which is the same as double quotation marks by default. (But double quotation marks can be placed in the delimiters)
② Variables cannot be parsed in single quotes, while variables can be parsed in double quotes and delimiters.
Note: When parsing variables in double quotes, you must note that "hahaha {$ num} Hahahaha" "hahaha $ {num} Hahahaha" is required after the variable name!
③ Double quotation marks can be placed in single quotes, and single quotation marks can be placed in double quotes. However, quotation marks of the same type cannot be placed.
④ Escape characters cannot be used in single quotes (except for single quotes '', Escape Character \ itself). escape characters can be used in double quotes.

6. pseudo types in PHP
Pseudo type: it is not a real data type. It only tells programmers which data types can be used to write help documents.
Mixed: indicates that the parameter can be of different data types.
Number: indicates that the parameter can be Integer or Float.
Callback: indicates that the parameter can be a callback function.

VII. Data type conversion in PHP
1. Automatic type conversion: indicates the Boolean, Null, String, and Other types during operation. It is automatically converted to Integer or Float type first.
Null --> 0
True --> 1
False --> 0
String to a number before a non-numeric character,
If not, convert it to 0 "123a" --> 123 "a123" --> 0

2. Forced type conversion: Convert variables to other types as needed.
$ New variable = (New Type) $ original variable; $ str = (String) 1;
// New type. You can use full spelling or abbreviations. Integer/int Boolean/bool.

The following types can be forcibly converted:
① Use () to declare strong conversion of new types:
(Int), (integer)-convert to integer
(Bool), (boolean)-convert to boolean
(Float), (double), (real)-convert to floating point type
(String)-convert to string
(Array)-convert to an array
(Object)-convert to object
② Use setType (); strong conversion of functions:
Bool setType (mixed var, String type); the first parameter represents a variable of any type, the second parameter represents a data type of the String type, and return a Boolean result.
③ Differences between the two conversions:
Type ①: Assign the converted result to the new variable;
Type ②: directly modify the Data Type of the original variable.


8. PHP judgment type
Is_bool (): determines whether it is a boolean type.
Is_int (), is_integer (), and is_long (): determines whether it is an integer.
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 it is an array
Is_object (): determines whether it is an object
Is_resource (): determines whether it is a resource type.
Is_null (): determines whether it is null
Is_scalar (): determines whether it is a scalar.
Is_numeric (): determines whether it is a numeric or numeric string of any type.
Is_callable (): determines whether the function name is valid.

9. Output statements in PHP
Echo "...... "; Output variable value
Var_dump (num); data type and value of the output variable [& Other Information]
Print_r (arr); used to print Arrays

// Single line comment


/*
* Multi-line comment
*/


/**
* Document comment
*/


# Script Annotation
# Echo "① form ";

10. constants in PHP
1. Constant definition: bool define (String constant name, mixed constant value [, whether bool is case sensitive]);
2. Notes for constants:
① Constant definition. Only define () functions can be used;
② Constant name, in principle, must be declared in uppercase. And must not contain the $ symbol ($ can only be a variable );
③ After a constant is declared, the global range is valid by default. No scope.
④ Constants cannot be modified and deleted! Unset, setType, and other functions are invalid.
⑤ Constants are case sensitive by default !!! However, you can set define's third parameter to true when declaring a constant to be case insensitive.
⑥ Constants must be defined using define () before they can be used. If a constant is not declared, it is converted to a constant string by default. However, there will be a warning.
Var_dump (NUM); --> String "NUM"
7. The constant value can only be a scalar Boolean String Float Integer.
3. You can use echo constant ("NUM") to read the constant value! Note !!!
You can use get_defined_constants () to obtain all defined constants !! Contains multiple constants defined by the system.

 

Okay ~~~ Today's content will be shared here first. May I help you ~

PS: I am a beginner in PHP. I hope to share, discuss, and learn with you and make progress together!

 

 


 

Author: XI Zhao hope
Source: http://www.cnblogs.com/hope666/

 

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.