Home>Article>Backend Development> What is the process of calling the interface in php
php calling interface process is: 1. Create a new php file; 2. Set the encoding format to utf-8; 3. Receive the parameters passed by calling the api interface through GET; 4. Use the switch statement to process GET Different values received; 5. Create a function and return the data returned after the api interface is called.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
#What is the process of calling the php interface?
php calling api interface tutorial:
Create a new php file, named test.php, as an api interface file, used to explain php calling api interface tutorial .
In the test.php file, use the header() method to set the encoding format of the page to utf-8 to avoid outputting Chinese garbled characters.
In the test.php file, receive the parameters passed by calling the api interface through GET. For example, $_GET['act'] is used here to receive the type of operation.
In the test.php file, use the switch statement to call different functions when GET receives different values. For example, when receiving $_GET['act' ] is func1, execute the one() function to return data, when receiving $_GET['act'] is func2, execute the two() function to return data, otherwise, execute the three() function to return data.
In the test.php file, create three functions one(), two(), and three() respectively to return the data returned after the api interface is called.
Open the test.php file in the browser and pass the parameters through act in GET mode. For example, to call the two() function of the api interface, the link is as follows:
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What is the process of calling the interface in php. For more information, please follow other related articles on the PHP Chinese website!