-4

我收到此错误:解析错误:语法错误,第 8 行 /Applications/XAMPP/xamppfiles/htdocs/core/functions/users.php 中的意外 T_STRING

我收到错误的代码是:

function recover($mode, $email) {
    $mode   = sanitize($mode);
    $email  = sanitize($email);

    $user_data = user_data(user_id_from_email($email), 'first_name', 'username');

    if ($mode == 'username') {
        email($email, 'Your username', 'Hello " . $user_data['first_name'] . ", \n\n Your username is: " . $user_data['username'] . " ');
    } elseif ($mode == 'password') {
        $generated_password = substr(md5(rand(999, 999999)), 0, 8);
        die($generated_password);
    }

}

我怎样才能解决这个问题?提前致谢

4

1 回答 1

2

以下行的语法不正确:

email($email, 'Your username', 'Hello " . $user_data['first_name'] . ", \n\n Your username is: " . $user_data['username'] . " ');

您可以将其替换为:

email($email, 'Your username', "Hello " . $user_data['first_name'] . ", \n\n Your username is: " . $user_data['username'] . " ");

但更简洁的方法是将变量嵌入到您的字符串中:

email($email, 'Your username', "Hello {$user_data['first_name']}, \n\n Your username is: {$user_data['username']} ");
于 2013-07-14T23:37:00.373 回答