使用preg_match更改eregi

时间:2012-11-24 04:15:38

标签: php string deprecated eregi

  

可能重复:
  How can I convert ereg expressions to preg in PHP?

这是我正在处理的代码:

foreach($domainextensions as $extension => $who) {                       
    $buffer = NULL;      
    if ($sock = fsockopen($who[0], 43) or die('sock' . $sock));
    fputs($sock, $domain.$extension . "\r\n");

    while( !feof($sock) ) {
        $buffer .= fgets($sock,128);
    }

    fclose($sock);

    if(preg_match($who[1],$buffer)) {
        echo '';
    }

错误是:

Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in somewhere.php 
if(preg_match($who[1],$buffer)){}

原始函数是eregi,eregi运行正常,但eregi已被取消:

if(eregi($who[1],$buffer)){}

如何在preg_match定义上更改定义的分隔符?

1 个答案:

答案 0 :(得分:0)

foreach($domainextensions as $extension => $who) {                       
                    $buffer = NULL;      
                    if ($sock = fsockopen($who[0], 43)
                    /
                    or die('sock' . $sock));
                    fputs($sock, $domain.$extension . "\r\n");

                            while( !feof($sock) )
                            {
                                    $buffer .= fgets($sock,128);
                            }

                    fclose($sock);

                    if(preg_match('/'.$who[1].'/i',$buffer))
                    {
                            echo '';
                    }

应该对模式进行分隔