There was no escaping in the original either. Also, I did assume that the list of replacements would grow to become pretty large. I wouldn't suggest doing this for a small list such as that given in the example. Robert Cummings wrote: > On Wed, 2007-11-07 at 14:33 +0000, Mark Summers wrote: > >> This is a first attempt but the general idea is that the regular >> expression matching is done in one operation and then str_replace() is >> called only as many times as required instead of once for every line in >> your list. Also, str_replace() is faster than ereg_replace(). >> >> <?php >> >> $replace = array( >> "ñ" => "n", >> "á" => "a", >> "é" => "e", >> "í" => "i", >> "ó" => "o", >> "ú" => "u" >> ); >> >> $link = "ssrsrsrsóererrereísddósdssú"; >> >> if (preg_match_all("/(".join("|", array_keys($replace)).")/", $link, >> $matches)) { >> $matches = array_unique($matches); >> >> foreach ($matches[0] as $match) { >> $link = str_replace($match, $replace[$match], $link); >> } >> } >> >> echo $link; >> >> ?> >> > > Don't do this, it's terribly inefficient and superfluously complicated. > There's no escaping of the strings either before jamming them into the > pattern. What happens if you need to replace '||||||||'. > > Cheers, > Rob. >