PHP 将字符串数据写入文件
PHP write string data to a file
如何使用 PHP 将数据写入文件?
这里有一个需要写的例子:
$filename = 'test.txt';
$keysize = '2048';
$dname = 'www.domain.com';
test.txt 文件的最终结果应该如下所示
[ req ]
bits = 2048
domain_name = www.domain.com
$output = "[ req ] \nbits = $keysize\ndomain_name = $dname";
file_put_contents($filename, $output);
\n
换行。我可以将 $keysize
等放在字符串本身中,因为我使用 "
来制作字符串 - 它不适用于 '
。请参阅此相关的 SO 问题:What is the difference between single-quoted and double-quoted strings in PHP?
PHP 脚本是:
<?php
$output = "[ req ]"."<br>";
$output .= "bits = ".$keysize."<br>";
$output .= "domain_name = ".$dname."<br>";
$handle = fopen($filename , 'w');
$write = fwrite($handle, $output);
fclose($handle);
?>
如何使用 PHP 将数据写入文件?
这里有一个需要写的例子:
$filename = 'test.txt';
$keysize = '2048';
$dname = 'www.domain.com';
test.txt 文件的最终结果应该如下所示
[ req ]
bits = 2048
domain_name = www.domain.com
$output = "[ req ] \nbits = $keysize\ndomain_name = $dname";
file_put_contents($filename, $output);
\n
换行。我可以将 $keysize
等放在字符串本身中,因为我使用 "
来制作字符串 - 它不适用于 '
。请参阅此相关的 SO 问题:What is the difference between single-quoted and double-quoted strings in PHP?
PHP 脚本是:
<?php
$output = "[ req ]"."<br>";
$output .= "bits = ".$keysize."<br>";
$output .= "domain_name = ".$dname."<br>";
$handle = fopen($filename , 'w');
$write = fwrite($handle, $output);
fclose($handle);
?>