解析错误:语法错误,意外T_STRING

时间:2013-07-14 23:32:47

标签: php

我收到此错误:解析错误:语法错误,第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);
    }

}

我该如何解决这个问题? 提前致谢

1 个答案:

答案 0 :(得分: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']} ");