Fixed all eregi to preg but one just eludes me

The old ereg to preg question, read much and fixed all but this one just no good, so what gives?

Old Code:

$E[‘subject’] = eregi_replace($key, $value, $E[‘subject’]);

New Code:

$E[‘subject’] = preg_replace(‘@’.$key.‘@i’, $value, $E[‘subject’]);

Any pointers much appreciated.


Sorry, should have explained this properly:

The error I get is: “Parameter mismatch, pattern is a string while replacement is an array”, though the previous code works fine.

The objective is to replace with values the tags enclosed by % in a template for an email. They are replaced with values from the $VAR array, so first we have:
while(list($key, $value) = each($VAR))
$re_this = “%var_”.$key.“%”;
$replace[$re_this] = $value;

Then we have:

while(list($key, $value) = each($replace))
$E[‘subject’] = preg_replace(‘@’.$key.‘@i’, $value, $E[‘subject’]);
$E[‘body_text’] = preg_replace(‘@’.$key.‘@i’, $value, $E[‘body_text’]);
$E[‘body_html’] = preg_replace(‘@’.$key.‘@i’, $value, $E[‘body_html’]);
Any clues?

That’s odd. The three parameters for eregi_replace are Strings so I would think that you would have gotten a similar error before as well.

You didn’t change how $value is obtained?

Thanks for your interest, I can confirm that all I need to do is change the three preg_replace lines back to previous and the script works absolutely fine. Weird.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.