The first step of php basic tutorial environment configuration and helloworld

PHP is a server-side scripting language. The full name is Hypertext Preprocessor for hypertext preprocessor.

It is said that php8 will be released soon. I will write a tutorial from php5 to php7 (the new features of php7 will be written after the basic tutorial is written) before 8 is released. Updates between PHP versions will add new features (the same for other languages), but the updated language will not feel unfamiliar in most cases. After the PHP version is updated, some functions will change the way of writing. Wait.

Compared with php5, php7 has improved or added many new features, such as doubled performance, reduced memory consumption, support for 64-bit, support for anonymous classes, and improved exception levels.

Note: The basic part of this series of tutorials will introduce the knowledge of php5, the latter part will explain the features of php7, and then the 8 features will be introduced after php8

Before php development, a deployment environment (Web server, PHP parser, database) is required. Because the deployment of each environment software is too troublesome, and this is only our learning environment, we can use some integrated environment software, such as phpstudy, wampserver, xampp, etc. I am using phpstudy here.

phpstudy

Insert picture description here
Download address of phpstudy (the old version is used here, the new version may have problems for novices): https://www.xp.cn/download.html

After downloading the corresponding system version environment, install phpstudy foolishly. After installation, find the installation directory of phpstudy. (The installation path cannot contain Chinese or spaces)
Insert picture description here
See the WWW directory, this directory is a root directory, the root directory of the website. The compiled php file needs to be stored in this directory.
Find the installed file and start the service: After
Insert picture description here
clicking WNMP to start, the red origin will turn blue.
At this time, you can open the browser, and then enter localhost or 127.0.0.1 to access, the following interface will appear:
Insert picture description here
Next, we will create a test directory under the WWW directory to store the php file we will write later.
Insert picture description here

NotePad++

Insert picture description here
After installing the environment, what is needed now is a tool to write PHP code. I use notepad myself, and I personally like it to be portable. If you have a favorite editor, of course, it’s okay to do it according to your preferences.
The download link of notepad is: https://notepad-plus-plus.org/downloads

Classic Hello World

At this time, it can be developed. Open notepad or your own editor.
Click File -> New:
Insert picture description here
Then enter:

<?php
	
?>

In the php script, it <?phpmeans the beginning of the ?>php script and the end of the php script. Write php code between the two.
Shortcut key ctrl+s to save, or click File -> Save to save:
Insert picture description hereThen a file save box pops up, in the save box, save the file in the test folder under the WWW directory (that is, the test file we just created) Folder), the file save type is PHP, naming it hello.php can save the file as a php file, because the suffix (.php) indicates the type of a file, named hello because this is the first php file, So
Insert picture description here
say hello to yourself first: here you need to pay attention, in the notepad, the upper left corner of the unsaved file will be red.
Insert picture description here
In this folder, the files are displayed.
Insert picture description here
Next, open the notepad editor and type the following code between <?php and ?>:

echo 'Hello Wolrd';

The complete code is as follows:

<?php
	echo "Hello World";
?>

The function of the above code is to output and display Hello Wolrd (that is, to display Hello Wolrd on the web page):
The function of echo is to display the output, and whatever character or string is appended will be displayed. Strings in php can be enclosed in double quotes or single quotes. Such as: "Hello Wolrd", "Hello Wolrd", "string".
Then you can access the php file we just wrote in the browser. Enter localhost in the browser to access the local site, that is , the website whose homepage is index.html under the WWW directory. Since we have created a new folder under the WWW directory, the following link can be used to access:

localhost/test/

The above access has not specified the file name. The name we set when we just saved it is hello. It is a php file. You need to specify the file name after localhost/test/, which is localhost/test/hello.php. Enter this website in the browser and then visit :
Insert picture description here
Successfully visited the page. Congratulations on entering the php world. The series will continue to be updated~ Welcome to follow, like, and favorite~

Guess you like

Origin blog.csdn.net/A757291228/article/details/107201703