为了账号安全,请及时绑定邮箱和手机立即绑定

如何编辑文本文件中一行的分割值?

如何编辑文本文件中一行的分割值?

PHP
米琪卡哇伊 2023-09-22 16:52:45
我有一个文本文件,其中包含 1 行具有此设置的内容:2222;3333两个值除以;.我如何编辑"splitted[0]"或"splitted[1]"保存文件中的新值?以下是我到目前为止所拥有的:<?php$file_handle = fopen("mytext.txt", "rw");while (!feof($file_handle) ){    $line_of_text = fgets($file_handle);    $parts = explode("\n", $line_of_text);    foreach ($parts as $str)    {        $str_parts = explode(';', $str); // Split string by ; into an array        array_shift($str_parts); // Remove first element        echo current($str_parts)."\n"; // echo current element and newline        // Same as $str_parts[0]    }}fclose($file_handle);?>
查看完整描述

1 回答

?
动漫人物

TA贡献1815条经验 获得超10个赞

<?php


$file = '2222;3333'; // that is your file

$file = explode(';', $file); // This split your file with delimiter ";"


foreach ($file as $newFile) {

    // Do whatever you want

    var_dump($newFile);

}


查看完整回答
反对 回复 2023-09-22
  • 1 回答
  • 0 关注
  • 52 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信