You are here: Re: Multiple scans through variable for search/replace « PHP Programming Language « IT news, forums, messages
Re: Multiple scans through variable for search/replace

Posted by Erwin Moller on 11/19/06 10:39

petersprc wrote:

> Hi,
>
> You probably won't notice any performance issues unless you have
> enormously high request volume... str_replace would be faster than a
> regex in general. There's also Smarty templates and straight PHP like
> so:
>
> mailer.php:
>
> foreach ($subscriptions as $sub) {
> ob_start();
> require('email-template.php');
> $text = ob_get_contents();
> ob_end_clean();
> mail($sub['email'], 'Subscription Confirmation', $text,
> "From: My Site <info@mysite.com>");
> }
>
> email-template.php:
>
> Dear <?= $sub['name'] ?>: You subscribed to <?= $sub['list'] ?>.

Hi,

Thanks for your response.
I'll stick to str_replace then. :-)

I cannot use direct writes/echo to the template in my situation. The
customer wants to see as little PHP as possible, so I must stick to the
***XXXX*** thingy. Nice/smart setup though. :-)

Regards,
Erwin Moller

>
> Erwin Moller wrote:
>> Hi Group,
>>
>> At the moment I am developing a app that uses templates.
>> In the templates I have placeholders like this:
>>
>> Dear ***FIRSTNAME***<br>
>> You have subscribed to ***LISTSUBSRIBE***.
>> etc
>>
>> The ***XXXX*** must be replaced with values created in my script.
>>
>> I am a bit worried about the speed and wonder which approach will be
>> fastest.
>> A straightforward solution would be to run a
>> str_replace($arrSearch,$arrReplace), where
>> $arrSearch contains the strings to be replaced by the corresponding
>> values in $arrReplace.
>>
>> Is this a fast solution?
>> Will a regexpression approach be faster?
>>
>> Does anybody have experience with this or advise?
>> Or should I just try a few and benchmark it?
>>
>> TIA!
>>
>> Regards,
>> Erwin Moller

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация