On Sun, 24 Aug 2003 14:42:01 +0200, you wrote: >I have a mailing script that sends individualised mails to users(some >users even get more than one mail). >I have a template html mail file. I individualise this by using >str_replace function. >It is really slow. >Can anyone point me to some performance tips?
Without knowing how you're doing it now, it's kinda hard. First tip is to use the right tool for the job - use mailing list software, not a scripting language optimised for HTML. 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)); Third tip is to make your template an array of strings rather than a single large array. Fourth tip is that you're probably running str_replace over the entire body of the text. At the very least, pre-process the template to find out which lines have substitutions in them, then only perform the replace on those lines in the main loop. Eg if we find that only lines 2, 3, and 15 need to be modified: $text = array (/* blah */); $lines = array (2, 3, 15); $replacements = array ("John", "[EMAIL PROTECTED]", "Viagra"); $i = 0; foreach ($lines as $line) { $text[$line] = sprintf ($text[$line], $replacements[$i++]); } BTW, do you realise you're sending HTML emails? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php