C# String Format Function For PHP


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.