function xsprintf_callback_example($userdata, &$pattern, &$pos, &$value, &$length)libphutil Technical Documentation ()
Example xsprintf() callback. When you call xsprintf, you must pass a callback like this one. xsprintf will invoke the callback when it encounters a conversion (like "%Z") in the pattern string.
Generally, this callback should examine $pattern[$pos] (which will contain the conversion character, like 'Z'), escape $value appropriately, and then replace $pattern[$pos] with an 's' so sprintf prints the escaped value as a string. However, more sophisticated behaviors are possible -- particularly, consuming multiple characters to allow for conversions like "%Ld". In this case, the callback needs to substr_replace the entire conversion with 's' and then update $length.
For example implementations, see xsprintf_command(), xsprintf_javascript() and xsprintf_query().
wild | $userdata | Arbitrary, optional userdata. This is whatever userdata was passed to @{function:xsprintf}. |
string | &$pattern | The pattern string being parsed. |
int | &$pos | The current character position in the string. |
wild | &$value | The value to convert. |
int | &$length | The string length. |
wild |
- Defined
- src/xsprintf/xsprintf.php:128