History log of /PHP-8.2/ext/standard/tests/strings/sprintf_star.phpt (Results 1 – 1 of 1)
Revision Date Author Comments
# 0221b8b2 21-Apr-2020 Nikita Popov

Add support for * width and precision in printf()

If * is used for width/precision in printf, then the width/precision
is provided by a printf argument instead of being part of the forma

Add support for * width and precision in printf()

If * is used for width/precision in printf, then the width/precision
is provided by a printf argument instead of being part of the format
string. Semantics generally match those of printf in C.

This can be used to easily reproduce PHP's float printing behavior:

// Locale-sensitive using precision ini setting.
// Used prior to PHP 8.0.
sprintf("%.*G", (int) ini_get('precision'), $float);

// Locale-insensitive using precision ini setting.
// Used since to PHP 8.0.
sprintf("%.*H", (int) ini_get('precision'), $float);

// Locale-insensitive using serialize_precision ini setting.
// Used in serialize(), json_encode() etc.
sprintf("%.*H", (int) ini_get('serialize_precision'), $float);

Closes GH-5432.

show more ...