note 93197 deleted from function.echo by danbrown
| From: | danbrown@php.net | Date: | Thu, 27 Aug 2009 22:11:08 +0000 |
| Subject: | note 93197 deleted from function.echo by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-159956@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
This will not give the output expected.
<?php
class String
{
public static function Format()
{
$argc = func_num_args();
$argv = func_get_args();
for ($arg_n = 0; $arg_n < $argc; $arg_n++)
{
$argv[0] = str_replace("\{$arg_n\}", $argv[$arg_n + 1], $argv[0]);
}
return $argv[0];
}
}
echo String::Format("My name is {0} and I am {1} years old", "Thomas", 18);
?>
This works, however:
$argv[0] = str_replace('{' . $arg_n . '}', $argv[$arg_n + 1], $argv[0]);