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 in plain text
PHP code starts with , and can be placed anywhere in the document
<?<span>php </span><span>// </span>?>
PHP statements end with a semicolon (;), and the closing tag of a PHP code block will automatically indicate the semicolon
<?<span>php echo </span><span>"</span><span>Hello World!</span><span>"</span><span>; </span>?>
PHP supports three types of comments, including two single-line comments and one multi-line comment
<?<span>php </span><span>//</span><span> 这是单行注释</span> <span> #这也是单行注释 </span><span>/*</span><span> 这是多行注释块 它横跨多行 </span><span>*/</span> ?>
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.
[Note] Echo and print are both language structures. You can use echo or echo() with or without parentheses, as well as print or print(), and there must be at least 2 characters between the echo or print keyword and the string. A space
<?<span>php echo </span><span>"</span><span><h2>PHP is fun!</h2></span><span>"</span><span>; echo </span><span>"</span><span>Hello world!<br></span><span>"</span><span>; echo </span><span>"</span><span>I'm about to learn PHP!<br></span><span>"</span><span>; echo </span><span>"</span><span>This</span><span>"</span>, <span>"</span><span> string</span><span>"</span>, <span>"</span><span> was</span><span>"</span>, <span>"</span><span> made</span><span>"</span>, <span>"</span><span> with multiple parameters.</span><span>"</span><span>; </span>?>
<?<span>php print </span><span>"</span><span><h2>PHP is fun!</h2></span><span>"</span><span>; print </span><span>"</span><span>Hello world!<br></span><span>"</span><span>; print </span><span>"</span><span>I'm about to learn PHP!<br></span><span>"</span><span>; </span><span>//</span><span>该行出错,因为print只能输出1个字符串</span> print <span>"</span><span>This</span><span>"</span>, <span>"</span><span> string</span><span>"</span>, <span>"</span><span> was</span><span>"</span>, <span>"</span><span> made</span><span>"</span>, <span>"</span><span> with multiple parameters.</span><span>"</span><span>; </span>?>
Unlike HTML and CSS, you can write calculation expressions in PHP
<?<span>php </span><span>//</span><span>36</span> echo <span>12</span>*<span>3</span><span>; </span>?>
In PHP, all user-defined functions, classes and keywords are not case-sensitive, but all variables are case-sensitive
<?<span>php </span><span>//</span><span>Hello World!</span> ECHO <span>"</span><span>Hello World!<br></span><span>"</span><span>; </span><span>//</span><span>Hello World!</span> echo <span>"</span><span>Hello World!<br></span><span>"</span><span>; </span><span>//</span><span>Hello World!</span> EcHo <span>"</span><span>Hello World!<br></span><span>"</span><span>; </span>?>
[Note] The . sign represents string concatenation. In other programming languages, the sign
is generally used.<?<span>php $color</span>=<span>"</span><span>red</span><span>"</span><span>; </span><span>//</span><span>My car is red</span> echo <span>"</span><span>My car is </span><span>"</span> . $color . <span>"</span><span><br></span><span>"</span><span>; </span><span>//</span><span>My house is </span> echo <span>"</span><span>My house is </span><span>"</span> . $COLOR . <span>"</span><span><br></span><span>"</span><span>; </span><span>//</span><span>My boat is</span> echo <span>"</span><span>My boat is </span><span>"</span> . $coLOR . <span>"</span><span><br></span><span>"</span><span>; </span>?>