如何编辑文本文件中一行的拆分值?
How edit splitted values of a line in text file?
我有一个文本文件,其中包含 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);
?>
<?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);
}
我有一个文本文件,其中包含 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);
?>
<?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);
}