Skip to content

Instantly share code, notes, and snippets.

@tudisco
Created February 5, 2011 23:12
Show Gist options
  • Save tudisco/812907 to your computer and use it in GitHub Desktop.
Save tudisco/812907 to your computer and use it in GitHub Desktop.
C# String Format Function For PHP
<?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