PHP | preg_match():未知的修饰符'('在第38行的C:\ xampp \ htdocs \ Folder \ index.php中)

时间:2016-11-17 17:11:14

标签: php lightopenid

我试图让人们使用以下代码登录:

<?php
 require './includes/lightopenid/openid.php'; 

$_STEAMAPI = "MyKey";

try {
    $openid = new LightOpenID('localhost');
    if(!$openid->mode) {
        if(isset($_GET['login'])) {
            $openid->identity = 'http://steamcommunity.com/openid/?l=english';
            header('Location: ' . $openid->authUrl());
        } else {
            echo "<h2>Connect to Steam</h2>";
            echo "<form action='?login' method='post'>";
            echo "<input type='image' src='http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_small.png'>";
            echo "</form>";
        }
    } elseif($openid->mode == 'cancel') {
        echo 'User has canceled authentication!';
    } else {
        if($openid->validate()) {
            echo "User is logged in.\n";

                $id = $openid->identity;
                $ptn = "/^http:\/\/steamcommunity\.com\/openid\/id/(7[0-9]{15,25}+)$/";
                preg_match($ptn, $id, $matches);      
                $url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$_STEAMAPI&steamids=$matches[1]";
                $json_object= file_get_contents($url);
                $json_decoded = json_decode($json_object);
                foreach ($json_decoded->response->players as $player) {

                }

        } else {
            echo "User is not logged in.\n";
        }
    }
} catch(ErrorException $e) {
    echo $e->getMessage();
}

?>

我收到此错误:

  

PHP | preg_match():未知的修饰符&#39;(&#39;在第38行的C:\ xampp \ htdocs \ Folder \ index.php中

我无法找到问题!我知道问题所在的 ,但是我发现的事情并没有发现任何问题。原因是什么,我该如何解决?

1 个答案:

答案 0 :(得分:0)

你在模式上忘了“/”之前的一个“\”:

$ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";

所以php认为“/(”是一个修饰符:http://php.net/manual/sr/reference.pcre.pattern.modifiers.php