newbtophp Posted August 10, 2010 Share Posted August 10, 2010 Im using func_get_args, but it gives an error?: Too few arguments?, when its correct (as the number of %s = the number of values within $args) <?php function sprintify() { global $urls; $args = func_get_args(); $input = $args[0]; unset($args[0]); return sprintf($urls[$input], implode(', ', $args)); } echo sprintify('default', 46, 464, 46); /* For your information: $urls['default'] = '%s/%s/%s'; */ ?> Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 10, 2010 Share Posted August 10, 2010 echo sprintify($urls['default'], 46, 464, 46); Quote Link to comment Share on other sites More sharing options...
newbtophp Posted August 10, 2010 Author Share Posted August 10, 2010 echo sprintify($urls['default'], 46, 464, 46); Im trying to make the first parem the array key, and then that value of that array is extracted within the function, refer to the first post. Cheers Quote Link to comment Share on other sites More sharing options...
Wolphie Posted August 10, 2010 Share Posted August 10, 2010 Try this: <?php function sprintify($args) { global $urls; $args = func_get_args(); $input = array_shift($args); return vsprintf($urls[$input], $args); } echo sprintify('default', 46, 464, 46); ?> Quote Link to comment Share on other sites More sharing options...
newbtophp Posted August 10, 2010 Author Share Posted August 10, 2010 Gr8 Wolphie that worked Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.