PHP fwrite新行 [英] PHP fwrite new line
本文介绍了PHP fwrite新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将用户名和密码写入txt文件中的新行. 输出应该是txt文件中的类似内容. 我知道这不是很安全,但这只是出于学习目的
I'm trying to write username and password to a new line in a txt file. The output should be something like this in the txt file. I know this is not very secure but its just for learning purposes
Sebastian password
John hfsjaijn
这是我到目前为止所拥有的
This is what i have so far
if(isset($_GET['register'])) //
{
$user = $_GET['username'];
$password=$_GET['password'];
$fh = fopen("file.txt","a+");
fwrite($fh,$user."\n"); //write to txtfile
fwrite($fh,$password."\n"); // write to txtfile
fclose($fh);
}
这是解决方案
Here's the solution
if(isset($_POST['register'])) //
{
$user = $_POST['username'];
$password=$_POST['password'].PHP_EOL;
$fh = fopen("file.txt","a+");
fwrite($fh,$user." ".$password); //write to txtfile
fclose($fh);
}
?>
推荐答案
使用 PHP_EOL
产生\r\n
或\n
$data = 'my data' . PHP_EOL . 'my data';
$fp = fopen('my_file', 'a');
fwrite($fp, $data);
fclose($fp);
//文件输出
my data
my data
这篇关于PHP fwrite新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文