News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

David Sklar's Blog:
Fast Multiple String Replacement in PHP
October 01, 2010 @ 10:09:40

David Sklar has a new post to his blog today sharing an extension he's created to make replacing strings in PHP a much faster task - Boxwood.

A straightforward way to do [string replacement] in PHP is to pass an array of words to look for and their replacements to a function like str_replace() or str_ireplace(). Or, similarly, use a regular expression that gloms the search terms together (and potentially checks word boundaries.) There are assorted WordPress plugins that work like this. The problem with this approach is that it's really slow. Especially if you have a lot of words you're looking for. The amount of time it takes to do the search and replace grows in proportion to the number of words you're looking for. This is particularly unfortunate because usually, none of the words are ever found!

With the Boxwood extension, the word list can be as long as needed because it uses an ordered tree structure (trie) to parse the entire tree only once so there's much less overhead.

0 comments voice your opinion now!
multiple string replacement extension boxwood


blog comments powered by Disqus

Similar Posts

Mohammad Emran Hasan: Concurrent HTTP requests in PHP using pecl_http

Lukas Smith's Blog: YAML and PHP

Clay Loveless' Blog: Monitor PHP Extension Releases with Y! Pipes

Mark Kimsal's Blog: Addslashes(): don't call it a comeback

Pierre-Alain Joye's Blog: how to do not work around filter (don't be lazy :)


Community Events

Don't see your event here?
Let us know!


series php7 language api community list library release opinion framework interview version extension laravel introduction laravel5 unittest podcast voicesoftheelephpant example

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework