如何将文本写入 txt 文件 (codeigniter)
How to write a text to a txt file (codeigniter)
检查完此处的问题后,我发现我需要 write_file 才能将文本写入 .txt 文件。我还在 Google 上寻找了有关它的教程或示例,但找不到简单的。
你能基本解释一下如何在 Codeigniter 中向 .txt 文件写入内容吗?
例如,用户在注册表单上提交文本,然后用户编写的文本将显示在 users.txt 中。
在 codeIgniter 中有一个名为 file_helper.php
in system/helpers
的文件助手可以帮助您做到这一点:
$this->load->helper('file');
$data = 'My Text here';
if ( !write_file('./path/to/file.txt', $data)){
echo 'Unable to write the file';
}
关于 file_helper
的完整文档是 here。
来自文档:
$this->load->helper('file');
$data = 'Some file data';
if ( ! write_file('./path/to/file.php', $data))
{
echo 'Unable to write the file';
}
else
{
echo 'File written!';
}
检查完此处的问题后,我发现我需要 write_file 才能将文本写入 .txt 文件。我还在 Google 上寻找了有关它的教程或示例,但找不到简单的。
你能基本解释一下如何在 Codeigniter 中向 .txt 文件写入内容吗?
例如,用户在注册表单上提交文本,然后用户编写的文本将显示在 users.txt 中。
在 codeIgniter 中有一个名为 file_helper.php
in system/helpers
的文件助手可以帮助您做到这一点:
$this->load->helper('file');
$data = 'My Text here';
if ( !write_file('./path/to/file.txt', $data)){
echo 'Unable to write the file';
}
关于 file_helper
的完整文档是 here。
来自文档:
$this->load->helper('file');
$data = 'Some file data';
if ( ! write_file('./path/to/file.php', $data))
{
echo 'Unable to write the file';
}
else
{
echo 'File written!';
}