Function in php to get user input

下次还敢
Release: 2024-04-27 13:39:24
Original
383 people have browsed it

PHP provides a variety of functions for obtaining user input: 1. $_GET: Get data from the URL query string; 2. $_POST: Get data from the HTTP request body; 3. $_REQUEST: Combine $_GET and $_POST, handles various HTTP requests; 4. readfile(): Read data from the file; 5. stream_get_contents(): Get data from the file pointer or URL; 6. fgets() / freadline(): Read from the file pointer Get a row of data; 7. parse_str(): parse the query string.

Function in php to get user input

PHP functions to obtain user input

PHP provides a variety of functions to obtain user input, mainly including the following Several types:

1. $_GET

Gets data from the query string of the URL for GET requests. For example:

<code class="php"><?php
$name = $_GET["name"];
?></code>
Copy after login

2. $_POST

Gets data from the HTTP request body for POST requests. For example:

<code class="php"><?php
$email = $_POST["email"];
?></code>
Copy after login

3. $_REQUEST

merges $_GET and $_POST and can be used to handle various HTTP requests. For example:

<code class="php"><?php
$username = $_REQUEST["username"];
?></code>
Copy after login

4. readfile()

Read data from the file. For example:

<code class="php"><?php
$data = readfile("input.txt");
?></code>
Copy after login

5. stream_get_contents()

Get data from file pointer or URL. For example:

<code class="php"><?php
$handle = fopen("input.txt", "r");
$data = stream_get_contents($handle);
?></code>
Copy after login

6. fgets() / freadline()

Read a line of data from the file pointer. For example:

<code class="php"><?php
$handle = fopen("input.txt", "r");
$line = fgets($handle);
?></code>
Copy after login

7. parse_str()

Parse the query string into an array of key-value pairs. For example:

<code class="php"><?php
$data = "name=John&email=john@example.com";
parse_str($data, $params);
?></code>
Copy after login

The above is the detailed content of Function in php to get user input. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!