-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathexamples.xml
107 lines (95 loc) · 3.13 KB
/
examples.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: e0b70f68d03701ce531be0025af19cdcfe333782 Maintainer: mowangjuanzi Status: ready -->
<!-- CREDITS: Luffy -->
<appendix xml:id="outcontrol.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
&reftitle.examples;
<section xml:id="outcontrol.examples.basic">
<title>基本用法</title>
<para>
<example>
<title>输出控制举例</title>
<programlisting role="php">
<![CDATA[
<?php
ob_start();
echo "Hello\n";
setcookie("cookiename", "cookiedata");
ob_end_flush();
?>
]]>
</programlisting>
</example>
</para>
<para>
在上面的例子中,<function>echo</function> 函数的输出将一直被保存在输出缓冲区中直到调用
<function>ob_end_flush</function>。同时对 <function>setcookie</function>
的调用也成功存储了 cookie,而不会引起错误。(数据已发送到浏览器后,消息头通常无法发送。)
</para>
</section>
<section xml:id="outcontrol.examples.rewrite">
<title>输出重写用法</title>
<para>
自 PHP 7.1.0 起,<function>output_add_rewrite_var</function>、<function>output_reset_rewrite_vars</function>
使用专用的输出缓冲区。即不使用 <link linkend="ini.session.use-trans-sid">trans sid</link> 输出缓冲区。
</para>
<para>
<example>
<title>输出重写示例</title>
<programlisting role="php">
<![CDATA[
<?php
// 此代码仅适用于 PHP 7.1.0、7.0.10、5.6.25 及更高版本。
// HTTP_HOST 是默认目标主机。手动设置以使示例代码工作。
$_SERVER['HTTP_HOST'] = 'php.net';
// 输出重写仅重写表单。添加 a=href.
// 可以指定标签 tag_name=url_attr, e.g. img=src,iframe=src
// 设置间不允许有空格。
// 表单标签是添加隐藏输入的特殊标签。
ini_set('url_rewriter.tags','a=href,form=');
var_dump(ini_get('url_rewriter.tags'));
// This is added to URL and form
output_add_rewrite_var('test', 'value');
?>
<a href="//php.net/index.php?bug=1234">bug1234</a>
<form action="https://php.net/?bug=1234&edit=1" method="post">
<input type="text" name="title" />
</form>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
<a href="//php.net/?bug=1234&test=value">bug1234</a>
<form action="https://php.net/?bug=1234&edit=1" method="post"><input type="hidden" name="test" value="value" />
<input type="text" name="title" />
</form>
]]>
</screen>
</example>
</para>
<para>
自 PHP 7.1.0 起,输出重写函数有自己的 INI 设置:<link linkend="ini.url-rewriter.tags">url_rewriter.tags</link> 和 <link linkend="ini.url-rewriter.hosts">url_rewriter.hosts</link>。
</para>
</section>
</appendix>
<!-- 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
-->