saeid ezzati
saeid ezzati

Reputation: 249

why this code save file data in wrong structure? php

I have this code:

<?php
$a = file_get_contents('a.txt');
$a .= "test2\r\n";
file_put_contents('a.txt', $a);
var_dump( file_get_contents('a.txt')) ;
?>

and this is content of a.txt before executing the code:

test1

when run it this result showed to me in browser:

string 'test1
test2
' (length=14)

but when I open the a.txt by notepad I saw this content:

test1
test2
test2

and when I execute code again it saw this result in browser:

string 'test1
test2
test2
test2
' (length=28)

but content of a.txt after execute was this in notepad:

test1
test2
test2
test2
test2

but why?

I asked a similar question at why this code adds two point every time that executes but no one answered a good answer to me :((

Upvotes: 0

Views: 97

Answers (2)

saeid ezzati
saeid ezzati

Reputation: 249

finaly my problem solved.

I had two extensions on chrome which is cousing this problem.

1- Web Server Notifier

2- Web Technology Notifier

after disabling these two extensions my problem solved.

I found my answer from this page: php mail duplicates

Upvotes: 0

Rob
Rob

Reputation: 12872

You are always appending test2\r\n to what's already in the file.

Upvotes: 1

Related Questions