且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

故障排除“分隔符不得为字母数字或反斜杠"将ereg()更改为preg_match()时出错

更新时间:2023-02-18 17:07:54

  1. ereg已过时.不要使用它.
  2. preg函数都是"Perl正则表达式",这意味着您需要在正则表达式上具有某种开始和结束标记.通常是/#,但是任何非字母数字都可以.
  1. ereg is deprecated. Don't use it.
  2. The preg functions are all "Perl regular expressions" meaning you need to have some sort of beginning and end marker on your regex. Often this will be / or #, but any non alpha-numeric will do fine.

例如,这些将起作用:

preg_match("/foo/u",$needle,$haystack);
preg_match("#foo#i",$needle,$haystack);
preg_match("@foo@",$needle,$haystack);
preg_match("\$foo\$w",$needle,$haystack); // bad idea because `$` means something
                                          // in regex but it is valid anyway
                                          // also, they need to be escaped since
                                          // I'm using " instead of '

但这不会:

preg_match("foo",$needle,$haystack); // no delimiter!