Jump to content

Recommended Posts

Good evening,

 

I'm using the following code in order to write in a file :

 


$newfile="/home/newfile.txt";

$file = fopen ($newfile, "w");

//while() //I would like to place in a while, and EOF condition, but i don't know how to do that

fwrite($file, $ip);
fwrite($file, $newString);
fclose ($file);

 

 

as i see in many fwrite examples, usually they write oonly one thing in a file.

1. I would like to write an a) IP and a b )String. The above code works, but it doesn't places any space between the IP and the string e.g. 1.2.3.4How are you? (No space between them)

2. Also, with fwrite the previous recordings get erased by the new ones.

What shall i do for that? Shall i place an EOF in a while or shall i use another function?

 

Thanks  :)

$newfile="/home/newfile.txt";

$file = fopen ($newfile, "a");

$output = $ip." ".$newString;

fwrite($file, $output);

fclose ($file);

 

That will open the file in append mode and write the data at the end of existing data in the file.

 

Not sure why you would need the while, maybe you could clarify

 

$newfile="/home/newfile.txt";

$file = fopen ($newfile, "a");

$output = $ip." ".$newString;

fwrite($file, $output);

fclose ($file);

 

That will open the file in append mode and write the data at the end of existing data in the file.

 

Not sure why you would need the while, maybe you could clarify

 

 

Thanks, actually it worked!

It writes at the EOF, but how am i supposed to add a '\n' for every recording?

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.