Created
February 5, 2011 23:12
-
-
Save tudisco/812907 to your computer and use it in GitHub Desktop.
C# String Format Function For PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function Format($str){ | |
//count arguments that our function received | |
$count_args=func_num_args(); | |
//check if we have sufficient arguments | |
if($count_args==1){return $str;} | |
for($i=0;$i<$count_args-1;$i++){ | |
//get the argument value | |
$arg_value=func_get_arg($i+1); | |
//replace {$i} with the value of specific argument position | |
$str=str_replace("{{$i}}",$arg_value,$str); | |
} | |
return $str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment