output_add_rewrite_var()

output_add_rewrite_var() — Add URL rewriter values.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

This function starts the 'URL-Rewriter' output buffer handler if it is not active, stores the name and value parameters, and when the buffer is flushed rewrites the URLs and forms based on the applicable ini settings. Subsequent calls to this function will store all additional name/value pairs until the handler is turned off.

Signature

output_add_rewrite_var(string $name, string $value): bool

Parameters

ParameterTypeWhat it takes
$namestringThe variable name.
$valuestringThe variable value.

Return value

Returns true on success or false on failure.

Example

A runnable snippet:

ini_set('url_rewriter.tags', 'a=href,form='); 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());

Output:

<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 )

Changelog

VersionChange
7.1.0As of PHP 7.1.0, a dedicated output buffer is used, url_rewriter.tags is used solely for output functions and url_rewriter.hosts is available. Prior to PHP 7.1.0, rewrite variables set by output_add_rewrite_var() shared an output buffer with transparent session id support (see ...

See also

output_reset_rewrite_vars(), ob_flush(), ob_list_handlers()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page output_add_rewrite_var() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.