I am trying to use vsprintf () to output a formatted string, but I need to check that I have the correct number of arguments before running it to prevent the "Too few arguments" errors.
Essentially, I think I need a regex to count the number of type specifiers, but I'm pretty useless when it comes to regex, and I couldn't finance it, so I thought I'd give SO go go, :)
If you can’t come up with a better way, this method will match what I want.
function __insertVars($string, $vars = array()) {
$regex = '';
$total_req = count(preg_match($regex, $string));
if($total_req === count($vars)) {
return vsprintf($string, $vars);
}
}
Please tell me if you can come up with an easier way.