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

PHP | preg_match(): Unknown modifier '(' in C:\xampp\htdocs\Folder\index.php on line 38

我正在尝试让人们使用 Steam 登录,使用此代码:

<?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(): Unknown modifier '(' in C:\xampp\htdocs\Folder\index.php on line 38

我找不到问题!我知道 问题出在哪里,但我找不到任何问题。是什么原因,我该如何解决?

你在你的模式中忘记了“/)”前的一个“\”:

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

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