用法:void parse_str ( string $str [, array &$arr] )
parse_str用来解析(分离)URL中的查询字符串(Query String),所谓查询字符串是指一个URL中?后面的部分,如http://localhost/test/result.php?name=anve&age=21,则查询字符串就是“name=anve&age=21”。
当然在PHP里,你可以用$_GET数组来取得查询字符串的值,但有时候parse_str会方便些,特别是当查询字符串中的变量名(对应于上面例子中的name和age)不知道的时候。
index.html:
result.php:
立即学习“PHP免费学习笔记(深入)”;
</span><span style="COLOR: #000000">''</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">print_r</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$arr</span><span style="COLOR: #000000">); </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> $arr[''name'']和$arr[''age'']被正确赋值。</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #0000ff">echo</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">''</span><span style="COLOR: #000000">
另注:parse_str会自动进行urldecode(URL解码)。例如在index.html的name中输入“波波”,我的测试结果是:
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号