Return to Snippet

Revision: 40733
at February 6, 2011 10:10 by tudisco


Updated Code
<?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;
}

Revision: 40732
at February 6, 2011 09:59 by tudisco


Updated Code
<?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 self::$_str;
}

Revision: 40731
at February 6, 2011 09:59 by tudisco


Updated Code
<?php

public 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 self::$_str;
}

Revision: 40730
at February 6, 2011 09:58 by tudisco


Updated Code
<?php

public function FormatSimpler($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 self::$_str;
}

Revision: 40729
at February 6, 2011 09:57 by tudisco


Initial Code
<?php

public function FormatSimpler($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,self::$str);
	}

	return self::$_str;
}

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

Initial Description

                                

Initial Title
C# String Format Function For PHP

Initial Tags
php, format

Initial Language
PHP