Written in front
PHP is a powerful server-side scripting language for creating dynamic and interactive sites. PHP can contain text, HTML, CSS and PHP code, execute it on the server, and the result is returned to the browser as plain text
Code identification
PHP code starts with , and can be placed anywhere in the document
<?php // ?>
PHP statements end with a semicolon (;), and the closing tag of a PHP code block will automatically indicate the semicolon
<?php echo "Hello World!"; ?>
Notes
PHP supports three types of comments, including two single-line comments and one multi-line comment
<?php // 这是单行注释 #这也是单行注释 /* 这是多行注释块 它横跨多行 */ ?>
Output
In PHP, there are two basic output methods: echo and print
print can only output a string and always returns 1
Echo can output more than one string. Echo is slightly faster than print because it does not return any value.
Friendly reminder between scripts: echo and print are both language structures. You can use echo or echo() with or without parentheses, and print or print(), and echo or print There must be at least one space
between the keyword and the string<?php echo "<h2>PHP is fun!</h2>"; echo "Hello world!<br>"; echo "I'm about to learn PHP!<br>"; echo "This", " string", " was", " made", " with multiple parameters."; ?> <?php print "<h2>PHP is fun!</h2>"; print "Hello world!<br>"; print "I'm about to learn PHP!<br>"; //该行出错,因为print只能输出1个字符串 print "This", " string", " was", " made", " with multiple parameters."; ?>
Calculation expression
Unlike HTML and CSS, you can write calculation expressions in PHP
<?php //36 echo 12*3; ?>
Case
In PHP, all user-defined functions, classes and keywords are not case-sensitive, but all variables are case-sensitive
<?php //Hello World! ECHO "Hello World!<br>"; //Hello World! echo "Hello World!<br>"; //Hello World! EcHo "Hello World!<br>"; ?>
Bangkejia kindly reminds everyone to pay attention to : . sign represents string connection. In other programming languages, the sign
is generally used<?php $color="red"; //My car is red echo "My car is " . $color . "<br>"; //My house is echo "My house is " . $COLOR . "<br>"; //My boat is echo "My boat is " . $coLOR . "<br>"; ?>
The above content is the basic PHP syntax that the editor has shared with you. I hope it will be helpful to you. At the same time, I would like to thank you for your continued support of the Bangkejia website. I also wish you all a happy New Year. !