0

私はパターンを持っていますstatus: availableが、コロン記号がどういうわけか機能しません。このパターンを変更するには?

コードで何かを台無しにしました。見つけたら通知します。ありがとうございました

OK、コードを分解しました。ドメインの可用性のためのスクリプトを書いています。

<?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 を "available" に変更すると動作します!

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 に答える