1

我有以下代码:

function showUser(array $match) {
    global $db;
    $result = $row = $db->select("SELECT Id FROM users WHERE Name=?",
        array($match[1]));
    if ($result!==false) {
        return '<a href="show_profile.php?id=' . $row['Id'] . '"><strong>' . htmlspecialchars($match[1]) . '</strong></a>';
    }

    return $match[0];
}


$text = preg_replace('/\[b\](.*?)\[\/b\]/', '<strong>$1</strong>', $text);
$text = preg_replace('/\[i\](.*?)\[\/i\]/', '<em>$1</em>', $text);
$text = preg_replace('/\[u\](.*?)\[\/u\]/', '<u>$1</u>', $text);
$text = preg_replace_callback('/\[user\](.*?)\[\/user\]/', 'showUser', $text);

我想知道:这段代码安全吗?不打针之类的?或者我应该使用类似的东西:'/\[b\]([a-zA-Z0-9 -\[\]=]+?)\[\/b\]/'?谢谢!

4

0 回答 0