I want to know what is the best approach to edit a specific block of text in a text file ?
For example if the text file contains the following blocks:
[account]
disabled = 1
user = user1
pwd = 1234
id = 1
group = 11
[account]
disabled = 0
user = user2
pwd = 1234
id = 2
group = 21
We have two blocks of data , how can i reach for the example block that belongs to a specific user (usernames are unique) and change some values like user,disabled ...etc
if all the data can be placed in one line this would be much easier with the following function:
$Read = file($fileDir);
foreach ($Read as $LineNum => $line) {
$LineParts = explode(' ', $line);
if ($LineParts[0] == $username) {
//code goes here
}}
Is there something similar ,but at block level (multiple consecutive lines) ?
Note: a lot of you will suggest database, but this file will be read from specific process on the system , so this work is done along with the database.
Regards