note 103588 added to function.sprintf
| From: | andrejsstepanovs at gmail dot com | Date: | Thu, 21 Apr 2011 14:13:41 +0000 |
| Subject: | note 103588 added to function.sprintf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179043@lists.php.net to get a copy of this message | ||
Use this function to ignore warning "Too few arguments".
<?php
/**
* Ignores php E_WARNING "sprintf(): Too few arguments".
* If parameters is too fiew, then this function add extra empty parameter and try again.
* Working in recursion.
*
* @param string $template
* @param mixed $parameters
* @return string
*/
function my_sprintf($template, $parameters){
if(!function_exists('handleError')){//initialize new error handler function
function handleError($errno, $errstr, $errfile, $errline, array $errcontext){
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler('handleError');
}
if(!is_array($parameters)){//manage parameters to allow string
$parameters = array($parameters);
}
try{//trying to execute function. if warning is received, then add parameter
eval('$return = sprintf($template, "'.implode('","',
$parameters).'");');
return $return;
}catch(ErrorException $e){
array_push($parameters, null);
return my_sprintf($template, $parameters);
}
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 62.85.94.53
----
Manual Page -- http://www.php.net/manual/en/function.sprintf.php
Edit -- https://master.php.net/note/edit/103588
Del: integrated -- https://master.php.net/note/delete/103588/integrated
Del: useless -- https://master.php.net/note/delete/103588/useless
Del: bad code -- https://master.php.net/note/delete/103588/bad+code
Del: spam -- https://master.php.net/note/delete/103588/spam
Del: non-english -- https://master.php.net/note/delete/103588/non-english
Del: in docs -- https://master.php.net/note/delete/103588/in+docs
Del: other reasons-- https://master.php.net/note/delete/103588
Reject -- https://master.php.net/note/reject/103588
Search -- https://master.php.net/manage/user-notes.php