bradgrafelman wrote:The way I understood it, he wanted to go the other way around:
I'm afraid I'm at a loss as to what you mean; your code and mine produce the exact same results.
At any rate, and just for curiosity's sake, here's a speed comparison script:
$str = '';
for ($i = 0; $i < 100; $i++) {
$myarray[$i] = '**M(' . $i . ')**';
$str .= '/==m(' . $i . ')==/';
}
$start = microtime(true);
for ($n = 0; $n < 1000; $n++) {
$content = $str;
$content = preg_replace('/==m\(([0-9]+)\)==/e', '$myarray[$1]', $content);
}
echo 'preg_replace() - ' . (microtime(true) - $start) . '<br />';
$start = microtime(true);
for ($n = 0; $n < 1000; $n++) {
$content = $str;
foreach ($myarray as $key => $val) {
$content = str_replace('==m(' . $key . ')==', $val, $content);
}
}
echo 'str_replace() - ' . (microtime(true) - $start) . '<br />';
preg_replace() - 3.5291819572449
str_replace() - 2.9098439216614