A review of PHP6 basic syntax (with Demo attached)

Reference materials (mooc.com)

1. PHP code needs to be written in "<?" and "? >";

<?php
 Expression
?>

Just as writing a JavaScript scripting language needs to be written between < script > < script > tags,
The PHP code written in the page is written between the < PHP? > tags, but note that the following? > can be omitted.

2. Calculation expression:

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>php grammar</title>
    </head>
    <body>
        <p>
        <?php echo 23+6;?>
        </p>
    </body>
</html>

3. Another echo:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Echo Sentence</title>
</head>
<body>
<p>
 <?php echo 'Welcome to imooc!';?>
</p>
</body>
</html>

4. string

A string is a word or sentence enclosed in double quotation marks, such as "Hi,imooc!". You can output this string in PHP, like this:

<?php echo "Hi,imooc!";?>

It can also be enclosed in single quotation marks, like the following code:

<?php echo 'Hi,imooc!';?>

You can connect two characters with connectors like this:

<?php echo 'Hi,'.'imooc!';?>

Note: a connector can connect multiple strings. The above example is to split a string into two small strings, and then connect them with a connector.

In php, string connector is represented by dot (.), which is quite special. In other languages, it is represented by plus sign (+), such as JavaScirpt, Asp and C.

demo:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Character string</title>
</head>
<body>
<p>
      <?php  echo 'There is an order in hearing Tao'.',Specialized in art!'?>
</p>
</body>
</html>

5. PHP statement Terminator: in PHP programming, you need to add a semicolon at the end of each statement; (half width status;)

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>php Statement Terminator</title>
</head>
<body>
<p>
    <?php 
    echo "Welcome students!";
    echo "Welcome" . " to imooc!";
    echo 1+2+3+4+5;
    ?>
</p>
</body>
</html>

6. Comment statement: represented by double slash (/ /)

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>php Statement Terminator</title>
</head>
<body>
<p>
    <?php 
    //I'll add a note. Don't worry
    echo "Welcome students!";
    echo "Welcome" . " to imooc!";
    echo 1+2+3+4+5;
    ?>
</p>
</body>
</html>

Tags: PHP Javascript Programming

Posted on Wed, 04 Dec 2019 08:53:59 -0800 by rofl90