In .NET we have a great little function called String.Format that will transform a string and format it. For example, let's say I wanted to display the phrase "Posted at: Wed Jan 5, 2009." Typically you would write:

str = "Posted at: " + aDate.ToString("ddd MMM d, yyyy");

Instead, String.Format lets you do:

str = String.Format("Posted at: {0:ddd MM d, yyyy}", aDate);

Imagine a phrase that had a lot of things that needed to be formatted or concatenated, you'll find String.Format is pretty nice.

In PHP there isn't really a function like that, you're stuck with concatenating them. Usually that's fine, but for those of you that want to store substitutable strings in a database, or just have lots of strings to concatenate, you can use this.

It does not format dates, etc. (yet) like .NET, it only substitutes strings.

/**
  * Formats a string with zero-based placeholders
  * {0}, {1} etc corresponding to an array of arguments
  * Must pass in a string and 1 or more arguments
  */
function string_format($str) {
	// replaces str "Hello {0}, {1}, {0}" with strings, based on
	// index in array
	$numArgs = func_num_args() - 1;
	
	if($numArgs > 0) {
		$arg_list = array_slice(func_get_args(), 1);
		
		// start after $str
		for($i=0; $i < $numArgs; $i++) {
			$str = str_replace("{" . $i . "}", $arg_list[$i], $str);
		}
	}

	return $str;
}

Use it like so:

$phrase = "Apples: {0}, Oranges: {1}, Grapes: {2}, Apple/Orange Ratio: {0}/{1}";

echo string_format($phrase, 5, 6, 7);

// outputs
Apples: 5, Oranges: 6, Grapes: 7, Apple/Orange Ratio: 5/6

PHP also has a function called sprintf, which you can look into for your needs as well. It is a bit more strict, I am not sure whether you will run into type mismatches (example, using '%s' and passing in an integer). You can repeat placeholders and format them. The function above might be friendlier to .NET'rs using PHP and will substitute anything as it just performs a replace operation.