从URL获取GET值并将其保存在文件中

时间:2012-12-23 23:26:07

标签: php formatting lines

我想从网址获取GET值并将其存储在文件中。我只是无法以我想要的格式得到它。

代码:

<?php

    $emailaccount = $_GET['email'];
    $emailaccount .= '\n';

    file_put_contents($file, $emailaccount, FILE_APPEND | LOCK_EX);
    echo 'done' . PHP_EOL;

?>

网址如下:

www.website.com/index.php?email=account@gmail.com

我的* .txt文件应该看起来像:

1account@gmail.com
2account@gmail.com
3account@gmail.com

但我的文件看起来不像这样,每个值都在同一行,为什么?

1 个答案:

答案 0 :(得分:3)

$emailaccount .= '\n';更改为$emailaccount .= "\r\n";应该这样做。

修改

原因如下:\ r \ n用于系统兼容性,需要双引号才能让PHP将其解析为换行符而不是文字字符串。

相关问题