1
0
mirror of https://github.com/php/doc-zh.git synced 2026-03-24 15:12:20 +01:00
Files
mowangjuanzi 7f4398773e Update strings
2025-07-09 00:53:21 +08:00

193 lines
5.5 KiB
XML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: da15b6674ac1900c7d065bd746a04b53d7e963bf Maintainer: daijie Status: ready -->
<!-- CREDITS: Luffy, mowangjuanzi -->
<refentry xml:id="function.parse-str" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>parse_str</refname>
<refpurpose>解析 URL 查询字符串</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>void</type><methodname>parse_str</methodname>
<methodparam><type>string</type><parameter>string</parameter></methodparam>
<methodparam><type>array</type><parameter role="reference">result</parameter></methodparam>
</methodsynopsis>
<para>
如果 <parameter>string</parameter> 是通过 URL 传入的查询字符串,则将其解析,并将 key 设置到指定 <parameter>result</parameter>
数组中。如果未提供 <parameter>result</parameter> 数组,则会将值设置为当前作用域中的变量。
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>string</parameter></term>
<listitem>
<para>
输入的字符串。
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>result</parameter></term>
<listitem>
<para>
以引用方式传递的变量,该变量将设置为数组,包含从 <parameter>string</parameter> 中提取的 key-value
对。如果未传入 <parameter>result</parameter> 参数,则每个 key 都会在局部作用域中设置为单独的变量。
</para>
<warning>
<para>
极度<emphasis>不建议</emphasis>在没有 <parameter>result</parameter> 参数的情况下使用此函数,
并且在 PHP 7.2 中将<emphasis>废弃</emphasis>不设置参数的行为。PHP 8.0.0
起,<parameter>result</parameter> 参数是<emphasis>强制的</emphasis>
</para>
</warning>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.void;
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.0.0</entry>
<entry>
<parameter>result</parameter> 是必须项。
</entry>
</row>
<row>
<entry>7.2.0</entry>
<entry>
不带第二个参数的情况下使用 <function>parse_str</function> 会产生
<constant>E_DEPRECATED</constant> 警告。
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>parse_str</function> 的使用</title>
<programlisting role="php">
<![CDATA[
<?php
$str = "first=value&arr[]=foo+bar&arr[]=baz";
// 推荐用法
parse_str($str, $output);
echo $output['first'], PHP_EOL; // value
echo $output['arr'][0], PHP_EOL; // foo bar
echo $output['arr'][1], PHP_EOL; // baz
?>
]]>
</programlisting>
</example>
</para>
<para>
在创建数组 key 或局部变量时,参数名中的「空格」和「点」均会转换为下划线。这是因为 PHP
变量名不允许包含空格或点号,即使按推荐方式使用 <parameter>result</parameter>
参数传递数组,此规则依然适用。
<example>
<title><function>parse_str</function> 名称改写</title>
<programlisting role="php">
<![CDATA[
<?php
parse_str("My Value=Something", $output);
echo $output['My_Value']; // Something
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<note>
<para>
<function>parse_str</function> 是受 <link linkend="ini.max-input-vars">max_input_vars</link>
指令影响的。超过这个限制会触发一个 <constant>E_WARNING</constant>
超过限制的变量不会被添加到结果数组中。
默认值是 1000根据需要调整 <link linkend="ini.max-input-vars">max_input_vars</link>
</para>
</note>
<note>
<para>
填充到 <parameter>result</parameter> 数组中的所有值(如果未设置第二个参数,则为创建变量)均已按照与
<function>urldecode</function> 相同的规则进行了 URL 解码。
</para>
</note>
<note>
<para>
要获取当前请求的查询字符串,可以使用 <varname>$_SERVER['QUERY_STRING']</varname> 变量。此外建议阅读<link
linkend="language.variables.external">来自 PHP 之外的变量</link>的相关章节。
</para>
</note>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>parse_url</function></member>
<member><function>pathinfo</function></member>
<member><function>http_build_query</function></member>
<member><function>urldecode</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->