Posted By

tudisco on 02/06/11


Tagged

php format String


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

tudisco
danfinrud55


C# String Format Function For PHP


 / Published in: PHP
 

URL: http://www.pedrocorreia.net/mySnippets/php/A-Basic-PHP-String-Format

  1. <?php
  2.  
  3. function Format($str){
  4. //count arguments that our function received
  5. $count_args=func_num_args();
  6. //check if we have sufficient arguments
  7. if($count_args==1){return $str;}
  8.  
  9. for($i=0;$i<$count_args-1;$i++){
  10. //get the argument value
  11. $arg_value=func_get_arg($i+1);
  12. //replace {$i} with the value of specific argument position
  13. $str=str_replace("{{$i}}",$arg_value,$str);
  14. }
  15.  
  16. return $str;
  17. }

Report this snippet  

You need to login to post a comment.