dsfew215211 2016-01-29 01:39
浏览 144
已采纳

使用多个变量时遇到file_put_contents语法问题

I tried this:

file_put_contents("logs/login.log", "$date: ".$userow['UserName'] ($userow['GBS'])" logged in.".PHP_EOL, FILE_APPEND);

But I get this error:

<b>Parse error</b>:  syntax error, unexpected '&quot; logged in.&quot;' (T_CONSTANT_ENCAPSED_STRING)

I don't see what the problem is, there are 4 " in what to put in the login.log, and the syntax appears correct in text editors. I can't figure this out.

  • 写回答

2条回答 默认 最新

  • dongmu4591 2016-01-29 02:35
    关注

    You don't need any concatenation operators at all, except to add your constant. A double quoted string will parse out your array indices quite nicely:

    $logfile = "logs/login.log";
    $msg = "$date: $userow[UserName] ($userow[GBS]) logged in." . PHP_EOL;
    file_put_contents($logfile, $msg, FILE_APPEND);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?