我有一个csv文件(包括/ sbk.php,忽略扩展,它是一个csv),我读取和删除行。
该csv文件的示例是......
serial,lastid,url,short,other
01,without last ID,#,no scheduled search,no search criteria
02,without last ID,#,no scheduled search,no search criteria
03,without last ID,#,no scheduled search,no search criteria
它有大约50行。第一行用于定义数组中的标题,其余行被读入一个数组,将其从0起点提升到1.
阅读CSV不是问题。我还使用以下代码删除由id(第一个csv col)标识的行:
if (isset($_POST['button'.$sID.'del'])) {
/* cmd */ // $delLastID $delUrl $delShort $delOther cleans house for
$lines = file($_SERVER['DOCUMENT_ROOT'] . '/includes/sbk.php');
$words = ($sbk.','.$delLastID.','.$delUrl.','.$delShort.','.$delOther);
$result = '';
foreach($lines as $line) {
if(substr($line, 0, 2) == $sbk) {
$result .= $words."\n";
} else {
$result .= $line;
}
}
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/includes/sbk.php', $result);
echo '<script type="text/javascript">parent.location="tabs.php";</script>'; // return the user to tabs
}
在另一个脚本中,我通过文件读取并有一个巨大的表单供用户选择带有“保存”按钮的东西,它试图像上面那样用我的变量重写特定的行。< / p>
// $VarForSbkLastID it's $elID[1][0];
// $VarForSbkUrl it's htmlspecialchars($_SERVER['QUERY_STRING'])
$carVarVariant = ($allCarVars['variant']);
$VarForSbkShort = $carVarMake.' '.$carVarModel.' '.$carVarVariant.' '.$carVarPriceFrom.' '.$carVarPriceTo.' '.$carVarMileageFrom.' '.$carVarMileageTo.' '.$carVarRegFrom.' '.$carVarRegTo.' '.$carVarEngineSizeFrom.' '.$carVarEngineSizeTo.' '.$carVarEnginePowerFrom.' '.$carVarEnginePowerTo.' '.$carVarFuel.' '.$carVarColor.' '.$carVarRegion.' ';
$VarForSbkOther = $carVarCategory.' '.$carVarMake.' '.$carVarModel.' '.$carVarVariant.' '.$carVarPriceFrom.' '.$carVarPriceTo.' '.$carVarMileageFrom.' '.$carVarMileageTo.' '.$carVarRegFrom.' '.$carVarRegTo.' '.$carVarEngineSizeFrom.' '.$carVarEngineSizeTo.' '.$carVarEnginePowerFrom.' '.$carVarEnginePowerTo.' '.$carVarFuel.' '.$carVarGearbox.' '.$carVarDoors.' '.$carVarDriveType.' '.$carVarColor.' '.$carVarAirbags.' '.$carVarDamage.' '.$carVarEuroclass.' '.$carVarRegion.' ';
if (isset($_POST['buttonadd'])) {
$lines = file($_SERVER['DOCUMENT_ROOT'] . '/includes/sbk.php');
$words = ($refid2.','.$elID[1][0].','.htmlspecialchars($_SERVER['QUERY_STRING']).','.$VarForSbkShort.','.$VarForSbkOther);
$result = '';
foreach($lines as $line) {
if(substr($line, 0, 2) == $refid2) {
$result .= $words."\n";
} else {
$result .= $line;
}
}
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/includes/sbk.php', $result);
echo '<script type="text/javascript">parent.location="tabs.php";</script>'; // return the user to tabs
}
echo '<input type="submit" name="buttonadd" value="Save">';
嗯..我被卡住了,无法想象我在那里做错了什么,并且它在isset之后没有执行我的命令,比如在清理一条线时......
任何人
P.S。阅读我使用以下.. http://pastebin.com/69nfjKPM