今天在项目里面无意发现一个函数output_add_rewrite_var,这个函数很陌生,从来没有使用过,于是查阅了PHP官网的解释
此函数给URL重写机制添加名/值对。 这种名值对将被添加到URL(以GET参数的形式)和表单(以input隐藏域的形式),当透明URL重写用session.use_trans_sid 开启时同样可以添加到session ID。 要注意,绝对URL(http://example.com/..)不能被重写。
完全看不懂他在说些什么,于是看了下example
<?php
output_add_rewrite_var('var', 'value');
// some links
echo '<a href="file.php">link</a>
<a href="http://example.com">link2</a>';
// a form
echo '<form action="script.php" method="post">
<input type="text" name="var2" />
</form>';
print_r(ob_list_handlers());
?>
输出
<a href="file.php?var=value">link</a> <a href="http://example.com">link2</a> <form action="script.php" method="post"> <input type="hidden" name="var" value="value" /> <input type="text" name="var2" /> </form> Array ( [0] => URL-Rewriter )这个函数无非就是在href属性中添加了?var=value键值对(绝对路径不添加)在form表单里面添加了一个隐藏域而已,官网的解释是在让人无法理解。
而output_reset_rewrite_var函数相对就很好理解了reset故名思议就是重置操作,官网的解释和例子也比较好明白。