Some basic knowledge for getting started with PHP learning (a must-read for newbies)_PHP Tutorial

WBOY
Release: 2016-07-13 17:29:15
Original
1038 people have browsed it

1. PHP script code tags

PHP script is the content included in a pair of special tags in the file. For example, ASP is "<%....%>", PHP It can be seen as "".

However, in order to adapt to the XML standard to embed PHP into XML or Format tag In addition, PHP code blocks also support form of marking.



2. PHP command delimiter
Each statement of PHP needs to be separated by a semicolon ";", but for the PHP end mark "?> ;", because it automatically implies a semicolon, so there is no need to append a semicolon.

So, the format of a PHP script can be as follows:

/*
............ ;
/*
............ ;
............ ;
............ ;
............
*/
//注意最后一行可以没有分号
?>
............ ;
............ ;............ */
//Note that the last line can be without a semicolon
? >

3. PHP comments

PHP multi-line comments use "/* .... ..... */"
Single-line comments use "#" or "//"


Four, PHP output

echo "a";
echo (b);
echo ("c");
echo d;
?>
in ASP Use "<%=...%>" to quickly output a single line, or use "<%Response.Write("...")%>"

Use "echo directly in PHP" ()" or "print()", such as:
echo "a";
echo (b);
echo ("c");echo d;?>

will be output as "abcd", and all the above four types can be output normally.


But in ASP , especially echo "a"; and echo d; are both output as strings themselves, which is impossible. This requires understanding PHP variable definitions.

5. PHP variables
$a="123";
echo a;
echo $a;
?>


Like ASP, PHP variables can be used directly without defining them first. The type of the variable is automatically generated when assigning a value.
Various variables in PHP are preceded by “$”
to indicate the difference.
$a="123";
echo "$a";
echo $a;
?>
TBODY>
$a="123";echo a;echo $a;
?>

The input is "a123"
$a="123";
echo "$a$a";
?>

6. The difference between single quotes and double quotes in PHP

$a="123";echo "$a";
echo $a;
?>

The output is "
123$a
$a="123";
echo "$a$a";
?>
", where echo "$a" outputs the value of variable a, and echo $a outputs the value in single quotes The string itself.

$a="123";
$a="123";
echo "$a$a"";
?>
echo "$a$a";

?> The output is "123123
" not "123$a". Although it is $a, the variable placed under double quotes is still replaced.
So, it can be concluded that: As long as the variables in the content are in double quotes, they will be replaced; while those in single quotes will not be replaced in any way
.

If the content in double quotes needs to be escaped, use the "" prefix, such as "", "$", """. So to enter "123$a", it is

$a="123";echo "$a$a";

?>

Another example:

1, the separator comma ";" It’s easy to forget to write. 2, definition and use of variables. 3, usage of single quotes and double quotes.
http://www.bkjia.com/PHPjc/531686.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531686.htmlTechArticle1. PHP script code tag PHP script is the content included in a pair of special tags in the file, such as ASP "%....%", PHP can be regarded as "?...?". However, in order to adapt to the XML standard and embed PHP...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template