Home  >  Article  >  Backend Development  >  Learn the basic syntax of PHP on the front end

Learn the basic syntax of PHP on the front end

WBOY
WBOYOriginal
2016-07-29 09:08:16959browse

Directory
[1]Code identification[2]Comments[3]Output[4]Calculation expression[5]Case

Previous words

PHP is a powerful server-side for creating dynamic interactive sites Scripting language. PHP can contain text, HTML, CSS and PHP code, and is executed on the server. The result is returned to the browser in plain text. Placed anywhere in the document

<?<span>php
  </span><span>//
</span>?>
  PHP statements end with a semicolon (;), and the closing tag of the PHP code block will also automatically indicate the semicolon

<?<span>php
    echo </span><span>"</span><span>Hello World!</span><span>"</span><span>;
</span>?>
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>?>

Output

In PHP, there are two basic output methods: echo and print

 print can only output a string and always returns 1

 echo Able to 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 one space between the echo or print keyword and the string

<?<span>php
    echo </span><span>"</span><span><h2>PHP is fun!</h2><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>;
    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>?>

Calculated expression

Unlike HTML and CSS, calculated expressions can be written in PHP

<?<span>php
    </span><span>//</span><span>36</span>    echo <span>12</span>*<span>3</span><span>;
</span>?>
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>?>

  [Note] The . sign represents String concatenation, in other programming languages, generally uses the + sign

<?<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>?>

The above has introduced the basic syntax for learning PHP on the front end, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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