Hello, I am new here, and hope to learn and contribute a lot. Recently, I started learning PHP (about 2 weeks), and now I am coming to the fopen() function. Say that I wanted to create a new file for reading and writing, is this what I would do?

$newfile = fopen("http://www.mydomain.org/php/Practice/text.txt", "a+");

Thanks in advance for any help,
Philip

$handle = fopen("http://www.example.com/", "r+");
'r+' : Open for reading and writing; place the file pointer at the beginning of the file.

Just making sure though, is this what I would do if I didn't have a file named text.txt, and I wanted to create one? And is this what I would use for the url?

"http://www.mydomain.org/php/Practice/text.txt"

EDIT: Also, do I have to close the file with fclose after I open it?

Ok, sorry for the double post, but I think I got it right. Here is the code to open, write, and close a new file I have:

<?php

$newfile = fopen("http://mydomain.org/php/Practice/mydata.txt", "a+");

fwrite($newfile, "This is a new file.");

fclose($newfile);

echo "All done!";

?>

Is that right? And if it is, how do I know if it worked, because when I run it, I can't find that new file on my server

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.