Hello,
I am a noob to PHP and I was wondering. How do I save text from the
url to a text file? For example
http://www.mydomain.com/store.php?value=12334567
how do I save value to a text file?
Thanks a lot,
Robert
Saving to a text file an assigned value
Moderator: General Moderators
-
TheBentinel.com
- Forum Contributor
- Posts: 282
- Joined: Wed Mar 10, 2004 1:52 pm
- Location: Columbus, Ohio
Re: Saving to a text file an assigned value
You can use file_get_contents() to get the text into a variable, then use file_put_contents() to put it into a file.rob64464 wrote:Hello,
I am a noob to PHP and I was wondering. How do I save text from the
url to a text file? For example
http://www.mydomain.com/store.php?value=12334567
how do I save value to a text file?
Thanks a lot,
Robert
http://www.php.net/file_get_contents
http://www.php.net/file_put_contents
If your version of PHP doesn't support one or both of those, the manual pages give you alternatives.
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
[php_man]file_get_contents[/php_man]() is easy to use, and is availible for use in the latest stable release of 4.x.
However, [php_man]file_put_contents[/php_man]() is only found in version 5.x so you'll need to use [php_man]fopen[/php_man]()/[php_man]fwrite[/php_man]()/[php_man]fclose[/php_man]() to complete the task.
Goto the fopen manual page, there is some more details about writing to files and also demostration code. Don't forget to read the user notes too.
However, [php_man]file_put_contents[/php_man]() is only found in version 5.x so you'll need to use [php_man]fopen[/php_man]()/[php_man]fwrite[/php_man]()/[php_man]fclose[/php_man]() to complete the task.
Goto the fopen manual page, there is some more details about writing to files and also demostration code. Don't forget to read the user notes too.
Code: Select all
<?php
$log = "data.txt";
if(file_exists("$log")) {
$write = fopen($log, "r+");
fwrite($write, $value);
fclose($write);
} else {
echo "$log could not be found";
}
?>uses fopen, n fwrite to get the txt and write (as suggested)