You are here: Re: preg_replace help « All PHP « IT news, forums, messages
Re: preg_replace help

Posted by robert on 04/26/06 06:03

"Wolverine" <joshualross@gmail.com> wrote in message
news:1146019782.599172.94400@y43g2000cwc.googlegroups.com...
| It turns out it is almost twice as fast to build the two arrays of all
| users and do one str_replace. Using PEAR's benchmarking I ran stats
| and it showed the following method:
|
| $uid_search = array();
| $uid_replace = array();
| foreach ($result as $key => $arr) {
| array_push($uid_search, ';u='.$arr->ID_MEMBER.'"');
| array_push($uid_replace, ';user='.$arr->id.'"');
| }
| $buffer = str_replace($uid_search, $uid_replace, $buffer);
|
| to be faster in every test... nearing twice as fast to this
| method(which is adapted from your suggestion, thanks!):
|
| foreach ($result as $key => $arr) {
| $arr_user_ids[$arr->ID_MEMBER] = $arr->id;
| $buffer = str_replace(';u='.$arr->ID_MEMBER.'"',
| ';user='.$arr->id.'"', $buffer);
| }
|
| I'm happy with the result. It seems the most expensive thing is call
| to run preg_replace or str_replace. Best to pack every single thing
| you need into the search and replace arrays before calling these
| methods.
|
| I wish I had a memory benchmarking tool but I don't think this would
| ever come close to the 6MB limit.
|
| Thanks again for the help!


not a problem...i'm glad you ventured out and verified the best approach.
preg only hits the 6MB limit if the $buffer is that size...breaking out what
you're searching/replacing could help that if you fear that it every could
get that big.

glad it's working for you.

me

 

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

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