【问题标题】:PHP: how can I change variable content of a txt file?PHP:如何更改 txt 文件的变量内容?
【发布时间】:2020-05-31 08:46:55
【问题描述】:

我目前正在尝试找到一种解决方案来编辑​​ txt 文件的一列,问题是没有列“结尾?”。我需要将价格乘以 1.1 并将其替换为新值(我需要编辑 280,24378,07 的字段)

此 txt 每 12 小时更新一次,因此价格每 12 小时更改一次...

一行如下所示:

961983  5031713050124   44661802    3335    OKI 19  Lasertoner  schwarz OKI 44661802    1       ST  280,24  378,07                                  29.05.2020  Lager   Beschaffungsartikel nein

任何人有一个 sugesstion 我该怎么做?

【问题讨论】:

标签: php csv


【解决方案1】:

列的宽度是固定的吗?然后你可以使用preg_split 作为

$data = preg_split("/[\s,]+/", $input);

并在数组中搜索词 ST 并将接下来的四个字段递增为
$num = (int)$data[index] * 1.1; $data[index] = $num;

然后使用implode()作为
$input = implode("\number of spaces\",$data);再次构建字符串

请注意,这可能被视为 PHP 的伪代码,函数存在,但由于我不知道空格是否固定或写回 CSV 的方式,我无法编写确切的代码。

如果我不能准确地解决问题,请原谅我。

【讨论】:

    猜你喜欢
    • 2018-05-23
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多