I had to make a GUI which would allow my client to customise a greeting message. They understood that they would have to use %s to indicate where the user name would be presented. But when too many %s are specified sprintf fails with message Too few arguments.
Is there an option to either leave excess %s instances in the string or just replace them with an empty string?
// $greeting_template === 'Welcome to our site %s. Broken: %s'
$output = sprintf($greeting_template, $user_name);
Obviously there are other sprintf formatting templates, those should also fail gracefully.
You should make sure, that the message template is valid, instead of fixing broken ones
substr_count()Or you switch to a completely own string-template format like