How to check that vsprintf has the correct number of arguments before running

sk2x

New Member
I'm trying to use vsprintf() to output a formatted string, but I need to validate that I have the correct number of arguments before running it to prevent "Too few arguments" errors.In essence I think what I need is a regex to count the number of type specifiers, but I'm pretty useless when it comes to regex and I couldn't fund it anywhere so I thought I'd give SO a go. :)Unless you can think of a better way this method is along the lines of what I want.\[code\]function __insertVars($string, $vars = array()) { $regex = ''; $total_req = count(preg_match($regex, $string)); if($total_req === count($vars)) { return vsprintf($string, $vars); }}\[/code\]Please tell me if you can think of a simpler way.
 
Back
Top