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

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

/* 

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


教程链接:

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

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft