PHP中可以自动分割查询字符的Parse_str函数使用示例
PHP中可以自动分割查询字符的Parse_str函数使用示例
这篇文章主要介绍了PHP中可以自动分割查询字符的Parse_str函数使用示例,小编也没见过的一个函数,这下分割URL中的查询字符串就方便了,需要的朋友可以参考下
直接上代码:
代码如下:
$str = "1&errid=1&fee=2&balance=2582&fails=&msgid=634541149212681528&msg=全部发送成功。";
parse_str($str, $output);
echo $output['msgid']; //输出 634541149212681528
定义和用法
parse_str() 函数把查询字符串解析到变量中。
语法
parse_str(string,array)
参数 描述
string 必需。规定要解析的字符串。
array 可选。规定存储变量的数组名称。该参数指示变量存储到数组中。
提示和注释
注释:如果未设置 array 参数,由该函数设置的变量将覆盖已由同名变量。
注释:php.ini 中的 magic_quotes_gpc 设置影响该函数的输出。如果已启用,那么在 parse_str() 解析之前,变量会被 addslashes() 转换。
例子
例子 1
代码如下:
parse_str("id=23&name=John%20Adams");
echo $id."
";
echo $name;
?>
输出:
代码如下:
23
John Adams
例子 2
代码如下:
parse_str("id=23&name=John%20Adams",$myArray);
print_r($myArray);
?>
输出:
复制代码 代码如下:
Array
(
[id] => 23
[name] => John Adams
)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software