Two days ago and friends get-together, my friend put forward my blog since the main target is PHP beginners, should be appropriate to add suitable for PHP beginners article, and also saw many people on the Internet to ask how to learn PHP problem, today began to share with you the basic knowledge of PHP should learn.
In general, I intend to learn from the introduction of PHP, mainly in the following steps: Introduce the basic syntax of PHP, basic common functions of learning, PHP and MySQL database basic interaction between the operation, combined with an introduction to the basic example of PHP application. Less gossip, let's start with the basics of learning PHP's basic syntax.
Before you start learning PHP basics, be sure to install the configuration PHP running environment.
How does PHP embed in HTML ?
PHP as a web development technology, can be embedded in HTML to run, please see the following example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
? $title = "Basic grammar learning in the introductory PHP tutorial"; $content = "Mainly introduce PHP basic grammar knowledge"; ?> <title><?= $title?></title> <body> ? Echo $content; ?> </body> |
In the example above, the PHP code begins and ends with a PHP tag, which is used to tell the Web server where the PHP code begins and where it ends. There are four kinds of tags in PHP:
XML style :
PHP is recommended for use in the markup style. This style can be used in XML (Extensible Markup Language) documents.
Short Style :
This style of marking is the simplest, and I generally use this type. If it is turned off, you can find the Short_open_tag option through the php.ini configuration file and set it to on.
Script Style :
This tag is not unfamiliar if you have used Javascipt or VBScript, and you can use it if you can't support other markup styles in the HTML editor.
ASP Style :
This style also needs to be used on the PHP.ini profile settings change asp_tags option, which is turned off by default. This is designed to get used to the programming style of ASP or asp.net.
Second, thePHP statement
PHP statements and C language, are separated by semicolons, attention to the habit of JavaScript programming friends must not forget that the PHP statement must end with a semicolon, omitting the semicolon is a very common grammatical error.
Special case : in HTML embedded in PHP, such as the need to output a single variable, in addition to the normal use of the Echo statement, you can directly use
It is equivalent to the function of the Echo statement and does not need to end with a semicolon.
Third, note
PHP support for C, C + + and Shell scripting style annotations
C-style multiline comment
1 2 3 4
|
Basic grammar Learning for the/*title:php introductory course Keyword:php Introductory tutorials, Introductory PHP learning Author:david */ |
Multiline comments start with "/*", End of "/", multiline comments cannot be nested .
C + + style Single-line Comment
1
|
echo "title:php Basic grammar learning"; Basic grammar Learning for the title:php introductory course |
Shell script Style Single-line comment, starting with #
1
|
echo "title:php Basic grammar learning"; Basic Grammar Learning #Title:P HP Introductory Tutorials |
Iv. connections between strings, variables
In a PHP statement, when a statement needs to output the value of multiple variables or multiple strings, you can use ".", i.e.
1
|
echo "Title:". Basic Grammar Learning for introductory PHP tutorials "; |
V. error suppressor @
Mainly used to suppress some alarms, can be used in such places as functions, such as
If there is no @, a warning alarm is reported, and if there is an alarm, it needs to be handled, and if the PHP5 can throw an exception, then process it or you can activate the Track_errors option in the php.ini configuration file, set to ON, You can have the error message stored in the global variable $php_errormsg. PHP Error Reporting detailed
Six, the execution operator
That is, reverse single quotes ', and on the same key, PHP tries to treat the command between the reverse single quotes as a server command, such as
1 2
|
$output = ' dir c: '; echo "<pre>". $output. " </pre> "; |
This statement is used to output the directory structure of the C disk.
Special Note : If the shell_exec () function is disabled, the code above will report an error message: Shell_exec () has been disabled for security reasons, The workaround is to find the php.ini configuration file, find the disable_functions option, remove the shell_exec and restart Apache.
So far, PHP's most basic grammar introduction to this, we mainly introduced a number of commonly used PHP identifiers, the composition of PHP statements, PHP annotation How to apply, string, variable output between how to connect, as well as the error suppressor, the implementation of the operator how to use, The next time we share PHP basic syntax knowledge of PHP variables, constants of the basic knowledge.
Note : PHP Web Development Tutorials-leapsoul.cn Copyright, reproduced in the form of links to indicate the original source and this statement, thank you.