<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Output rewrite usage</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="outcontrol.examples.basic.html">Basic usage</a></div> <div class="next" style="text-align: right; float: right;"><a href="ref.outcontrol.html">Output Control Functions</a></div> <div class="up"><a href="outcontrol.examples.html">Examples</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="outcontrol.examples.rewrite" class="section"> <h2 class="title">Output rewrite usage</h2> <p class="para"> Since PHP 7.1.0, <span class="function"><a href="function.output-add-rewrite-var.html" class="function">output_add_rewrite_var()</a></span>, <span class="function"><a href="function.output-reset-rewrite-vars.html" class="function">output_reset_rewrite_vars()</a></span> use dedicated output buffer. i.e. It does not use <a href="session.configuration.html#ini.session.use-trans-sid" class="link">trans sid</a> output buffer. </p> <p class="para"> <div class="example" id="example-506"> <p><strong>Example #1 Output rewrite example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// This code works with PHP 7.1.0, 7.0.10, 5.6.25 and up.<br /><br />// HTTP_HOST is default target host. Set manually to make sample code works.<br /></span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'HTTP_HOST'</span><span style="color: #007700">] = </span><span style="color: #DD0000">'php.net'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Output rewriter only rewrite form. Add a=href.<br />// Tags can be specified tag_name=url_attr, e.g. img=src,iframe=src<br />// No space allowed between settings.<br />// Form tag is special tag that add hidden input.<br /></span><span style="color: #0000BB">ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'url_rewriter.tags'</span><span style="color: #007700">,</span><span style="color: #DD0000">'a=href,form='</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">'url_rewriter.tags'</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">// This is added to URL and form<br /></span><span style="color: #0000BB">output_add_rewrite_var</span><span style="color: #007700">(</span><span style="color: #DD0000">'test'</span><span style="color: #007700">, </span><span style="color: #DD0000">'value'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?><br /></span><a href="//php.net/index.php?bug=1234">bug1234</a><br /><form action="https://php.net/?bug=1234&edit=1" action="post"><br /> <input type="text" name="title" /><br /></form></span> </code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> <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> </pre></div> </div> </div> </p> <p class="para"> Since PHP 7.1.0, output rewrite functions have it's own INI settings, <a href="outcontrol.configuration.html#ini.url-rewriter.tags" class="link">url_rewriter.tags</a> and <a href="outcontrol.configuration.html#ini.url-rewriter.hosts" class="link">url_rewriter.hosts</a>. </p> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="outcontrol.examples.basic.html">Basic usage</a></div> <div class="next" style="text-align: right; float: right;"><a href="ref.outcontrol.html">Output Control Functions</a></div> <div class="up"><a href="outcontrol.examples.html">Examples</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>