Delimiter must not be alphanumeric or backslash php

Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash

1.出现提示的写法

$reg = "is";

$str = "This is a register book.";

var_dump($str); 

$str = preg_replace($reg, "@", $str);

var_dump($str);

2. 修改后的写法。

$reg = "/is/";

$str = "This is a register book.";

var_dump($str);

$str = preg_replace($reg, "@", $str);

var_dump($str);

分析:

php的匹配字符串是需要分隔符来分隔的。这个分隔符不能是字母数字和反斜线。其他的字符是可以的。

一般选择 / 做分隔符,添加分隔符后问题得到解决。

即:

$reg = "/is/";

原文地址:https://www.cnblogs.com/BigBigLiang/p/5472854.html