-5

Possible Duplicate:
Converting ereg expressions to preg
eregi_replace(“[\]”,'',$data) — what does this line do?

I am using phpmailer and it is using eregi_replace, I am trying to update this, would this be correct, I am not sure if I have the /i in the right place?.

$body = eregi_replace("[\]",'',$body);

would become:

$body = preg_replace("[\]",''/i,$body);
Community
  • 1
  • 1
Iain Simpson
  • 441
  • 4
  • 13
  • 29

3 Answers3

1

Your regex removes all \ from the body. It is not necessary to have that case insensitive, since \ does not have case. You would write that regex like:

$body = preg_replace('/\\\\/i', $body);

Not that you do not need the i as I said because their is no difference between a case insensitive and a case sensitive match here. Also note that the actual regular expression is just \. The / are delimiters and you need four backslashes, because they are in a PHP string so they become two literal backslashes \\ which is needed because the expression /\/ is invalid since the backslash escapes the end delimiter.

Paul
  • 139,544
  • 27
  • 275
  • 264
0

No. You'd have to write preg_replace('/\\/i', '', $body). This is assuming, of course, that you'd like to remove all backslashes inside the body.

Milad Naseri
  • 4,053
  • 1
  • 27
  • 39
0
$body = preg_replace("/[\\]/i","",$body);
MDEV
  • 10,730
  • 2
  • 33
  • 49
  • I get this error when I try using this >> – Iain Simpson Jan 07 '12 at 14:41
  • Warning: preg_replace() [function.preg-replace]: Compilation failed: missing terminating ] for character class at offset 3 in C:\server2go\server2go\htdocs\chandlers\components\com_jumi\views\application\view.html.php(38) : eval()'d code on line 9 – Iain Simpson Jan 07 '12 at 14:41
  • Ah yes, of course - sorry, use \\\\ in the square brackets – MDEV Jan 07 '12 at 14:46