On Sun, 24 Aug 2003 15:38:13 +0100, you wrote:

>Second tip is that sprintf() should be faster than str_replace(). Compare:
>
>$text = "Hello %s";
>$name = "John";
>
>echo (str_replace ("%s", $name, $text));
>echo (sprintf ($text, $name));

Thinking about it, straight concatenation should be faster than sprintf()

$text = "Hello %s, welcome to the list";
$text = explode ("%s", $text);
echo ($text[0] . $name . $text[1]);

The explode goes outside the main loop, of course. Pre-processing.

The downside is that the simpler (and faster) you make it, the more
assumptions you have to make about the template (in this case, one
substitution per line and the substitution can't be the first or last
element on the line).

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to