Home > Backend Development > PHP Tutorial > Front-end learning PHP basic syntax, front-end php syntax_PHP tutorial

Front-end learning PHP basic syntax, front-end php syntax_PHP tutorial

WBOY
Release: 2016-07-12 09:02:00
Original
910 people have browsed it

Learn the basic syntax of PHP on the front end, front-end PHP syntax

Contents
[1] Code identification [2] Comment [3] Output [4] Calculation expression [5] Case

Previous words

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

Code identification

PHP code starts with , and can be placed anywhere in the document

<?<span>php
  </span><span>//
</span>?>
Copy after login

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>?>
Copy after login

Comments

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>
?>
Copy after login

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.

[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>?>
Copy after login
<?<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>?>
Copy after login

Calculation expression

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>?>
Copy after login

Case

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>?>
Copy after login

[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>?>
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1087042.htmlTechArticleFront-end learning PHP basic syntax, front-end PHP syntax directory [1] code identification [2] comments [3] output [4] Calculating expressions [5] Case As mentioned above, PHP is a powerful tool for creating dynamic interactive sites...
source:php.cn
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