php . .使用文本文件在分号表中插入(追加)一条记录
php... inserting (appending) a record into a semicolon table using a text file?
我正在使用一个文本文件,里面有一个分号表…我已经学会了如何获取我的数据。特别是抓取任何我需要的列…
<?php
$statfile=$_GET['scd'];
if ($statfile=='')
{
$statfile="/et3mach/status.txt";
}
$temps = array();
$brdhover = array();
if (($handle = fopen($statfile, "r")) !== FALSE)
{
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE)
{
if(substr(trim($data[0]), 0, 3) == 'BRD')
{
$board = trim($data[0]); // get the index (e.g "BRD 0") & strip leading or trailing blanks
$temp = trim($data[10]); // the tempreture data is the 10th field; trim that also, to be safe.
$temps[ $board ] = $temp;
$brdhover[ $board ] = $data[11]; // Field 11 is the "hover" text; don't trim that for now...
}
}
fclose($handle);
}
?>
但是插入更困难,所有我能想到的是插入一个记录到一个文本文件…
<?php
$companyfile = "data/company.txt";
if (isset($_POST['company']))
{
$newData = nl2br(htmlspecialchars($_POST['company']));
$handle = fopen($companyfile, "w");
fwrite($handle, $newData);
fclose($handle);
}
// ----------------------------
if (file_exists($companyfile)) {
$companyData = file_get_contents($companyfile);
}
我如何结合这两个功能,以便我可以使用html表单插入和追加消息?在本例中,我有一个带有一列的分号表。
对于fopen()
、fwrite()
、fclose()
,可以使用带有FILE_APPEND
标志的包装函数file_put_contents,如下图所示
file_put_contents($file, $content, FILE_APPEND);
相关文章:
- 表追加而不附加最后一个元素
- 将样式表插入iframe
- Ckeditor-plugin:插入虚假元素add不情愿<p>标签前后
- 如何动态插入jquery代码
- 动态插入的表:JQuery未检测到最后一行
- 使用JavaScript动态插入DIV的成本有多高
- 带有填充属性的SVG矩形显示在包含元素的上方插入框阴影
- 将对象动态插入到现有对象中
- 将数组中的值插入到表中
- 在 Java 中的 JavaScript 函数中插入 Wicket 值
- 我如何在数字插入中使用逗号,这样它就不会'不要破坏我的输入字段
- 追加到文档中尚未插入的新节点
- 通过追加将方法链接到新插入的元素
- D3.js - 根据当前基准面追加或插入元素
- php . .使用文本文件在分号表中插入(追加)一条记录
- 将PHP foreach插入到jquery追加函数中
- 如何在for循环中通过追加将多个元素插入到一个元素中
- javascript img元素插入(替换,而不是追加)
- 追加子项和插入之前
- 文本框是不保持值或丢失值后张贴回通过Javascript插入或追加的teleerik文本框