Home > php教程 > php手册 > php 把查询字符串解析到变量中

php 把查询字符串解析到变量中

WBOY
Release: 2016-06-02 09:14:13
Original
1291 people have browsed it

parse_str() 函数把查询字符串解析到变量中.

语法:parse_str(string,array)

注释:如果未设置 array 参数,由该函数设置的变量将覆盖已由同名变量,实例代码如下:

*/ 

parse_str("id=23&name=john%20adams"); 
echo $id."<br />"; 
echo $name; 
 
//23 
//john 
 
$str="first=value&arr[]=foo+bar&arr[]=baz";    //定义字符串 
parse_str($str);          //把字符串解析为变量 
echo $first;          //输出$first的值value 
echo "<br>"; 
echo $arr[0];          //输出$arr[0]的值foo bar 
echo "<br>"; 
echo $arr[1];          //输出$arr[1]的值baz 
echo "<br>"; 
parse_str($str,$output);        //把字符串解析的变量存储在$output中 
echo $output[&#39;first&#39;];         //输出$first的值value 
echo "<br>"; 
echo $output[&#39;arr&#39;][0];         //输出$arr[0]的值foo bar 
echo "<br>"; 
echo $output[&#39;arr&#39;][1];         //输出$arr[1]的值baz
Copy after login

/* 

注释:php.ini 中的 magic_quotes_gpc 设置影响该函数的输出,如果已启用,那么在 parse_str() 解析之前,变量会被 addslashes() 转换.


教程链接:

随意转载~但请保留教程地址★

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template