2

My code was

if(eregi($pattern,$file)){ $out['file'][]=$file; }else

But is doesn't work in php 5.3, it shows the alert

Function eregi() is deprecated

so I changed to

if(preg_match($pattern,$file)){ $out['file'][]=$file; }else

But now it shows

preg_match(): No ending delimiter '.' found

Did I enter any wrong syntax?

4

1 に答える 1

3

パターンには、それを囲む何らかの区切り文字が必要です。

if(preg_match('/' . $pattern . '/',$file)){

/が典型的ですが、「非英数字、非バックスラッシュ、非空白文字」を使用できます。区切り文字が$patternそれ自体に含まれていないことを確認してください。

したがって、パターンがhttp://(.*)で、すでに/文字が含まれている場合は、次のような別のものを選択することをお勧めします~

if(preg_match('~' . $pattern . '~',$file)){

または、@jensgramが以下に記しているように、パターンに特定の区切り文字が含まれていないことを保証できない場合は、次のようにpreg_quote()を使用してパターン内のそれらの文字をエスケープできます。

if(preg_match('~' . preg_quote($pattern, '~') . '~',$file)){

また、(大文字と小文字を区別しない) を使用しているため、パターンの区切り記号の外側に、大文字と小文字を区別しないための修飾子eregi()を追加する必要があります。i

if(preg_match('~' . $pattern . '~i',$file)){
于 2011-08-30T15:53:15.713 に答える