Our first piece of PHP code

This code is very magical, one sentence can turn into a web page. This is our first piece of code to get started with PHP.

Now you can create a new file in the root directory of the web server (D:\phpStudy\www). The name of the file is: abc.php.

Write the following code in this abc.php file.

<?php

phpinfo();

?>

You can enter your server address in the browser address bar. We currently use our own computer as a web server. You can enter in the address:

http://www.php.cn/abc.php

You will see a web page. The content of the web page is usually as shown below:

QQ截图20161114090737.png

Translate this sentence in Chinese for you

<?php

phpinfo();

?>

Just now we saw that this code has generated a web page. I don’t understand what it means, so now I’ll explain it to you bit by bit.

<?php
//这句话是说明从此处【尖括号、问号、PHP】这5个字符开始,往下的部份是PHP代码。
?>

However, encountering the [question mark, angle brackets] above indicates that the PHP code has been written. The rest of it has nothing to do with my PHP.

Have you guys watched it now? Excuse me: phpinfo() is followed by a semicolon (;), and there are two carriage returns on the line before and after phpinfo(). What does this mean?

Now let me tell you the answer:

  • phpinfo is a function (function). This function (function) will display detailed PHP information of the current computer (server) . I will explain the phpinfo() function to you later. This function must be remembered by everyone!

  • The computer is a very stupid thing. He needs us to tell him manually that the code is finished. We use a semicolon (;) to tell him that the code is finished. Therefore, as soon as we finish writing a piece of code, we need to add a semicolon (;) after it.

  • The carriage return and blank lines in the two lines before and after are to make the code more beautiful and avoid stacking together, which makes people look uncomfortable. In fact, it doesn’t matter how many carriage returns and blank lines you have in the middle, as long as it looks good. PHP's syntax interpreter (the core part of PHP) will not handle these blank lines.


Note:

  • The code part of php must be written in half-width English. Many people tend to write it in full-width English and Symbols cause PHP code to report errors.

  • The last line of PHP code may or may not contain a semicolon. Because many learners, especially beginners, often make a mistake: writing a line of code without adding a semicolon. Therefore, it is easy to report errors. We usually stipulate in the company that after a line of code is written, a semicolon must be added.

  • PHP can also have a concise declaration mode. We focus on code exercises at this stage. Regarding the environment configuration issue, it is not recommended to study for the time being. In the following chapters, we will explain it specifically.

  • Above, it is very easy to accidentally cause errors in actual development.

###When we write the file abc.php and name it, we only use English half-foot characters (a-zA-Z0-9_-) to name the file. Do not use Chinese characters in file names, do not use special appendixes, do not add spaces in the middle, and strictly distinguish between sizes. #########
Continuing Learning
||
<?php phpinfo(); ?>
submitReset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!