Jump to content

[PHP] Как изменить данные в файле


Recommended Posts

Нужно в строке где первый столбец == "name1" поменять yes на no.

файл db.txt.

name1|1@mail.ru|name2|yes
name3|2@mail.ru|name3|yes
name4|3@mail.ru|name4|yes

 

$glob = "name1";
$data = file('db.txt');
foreach ($data as $row) {
   $cols = explode('|', $row);
   if (strcmp($glob, $cols[0]) === 0) {
       $cols[3] = str_replace("yes", "no", $cols[3]);
       $row = implode('|', $cols);
   }
}

file_put_contents('1.txt', $data);

 

Вроде и в цикл заходиьт, но данные такие же. НЕ меняет yes на no

Edited by ahvahsky2008
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...