0

我有一个模式status: available,但冒号符号不起作用。如何修改这个模式?

我在代码中弄乱了一些东西,当我找到它时会通知你。谢谢你

好的,我分解了代码。我正在为域可用性编写脚本。

<?php
$server = 'whois.cira.ca';
$pattern = 'status: available';

$domain = 'nonexistingdomain';
$extension = '.ca';

$buffer = NULL;
$sock = fsockopen($server, 43) or die('Error Connecting To Server: ' . $server);
fputs($sock, $domain.$extension . "\r\n");

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

//If I give a value localy to $buffer (like below) it works, but if $buffer takes the value from fgets() function it wont
$buffer = "Domain name: nonexistingdomain.ca Domain status: available % WHOIS look-up made at 2013-01-16 12:35:45 (GMT) % % Use of CIRA's WHOIS service is governed by the Terms of Use in its Legal % Notice, available at http://www.cira.ca/legal-notice/?lang=en % % (c) 2013 Canadian Internet Registration Authority, (http://www.cira.ca/) NO";

fclose($sock);

if(preg_match("/$pattern/", $buffer))
    echo "YEP";
else
    echo "NO";
?>

如果我将 $pattern 更改为“可用”,它会起作用!

4

1 回答 1

0

好像你缺少一个分隔符。

尝试这个:

<?php

$pattern = '/status: available/';

$string = "String1: status: available";
$string1 = "String2: status: unavailable";


if (preg_match($pattern,$string))
    echo 'String1 matches<br>';
else
    echo 'String1 does not match<br>';

if (preg_match($pattern,$string1))
    echo 'String2 matches<br>';
else
    echo 'String 2 does not match<br>';
?>

给出以下输出:

String1 matches

String 2 does not match

于 2013-01-16T10:24:51.600 回答