Jump to content

Archived

This topic is now archived and is closed to further replies.

AdRock

How do get contents of a text file into a variable [RESOLVED]

Recommended Posts

I have a text file which basically holds a number
I would like to use that number to be a variable but am having trouble getting it to work

here is my code to write to the text file
[code]<?php
$name = $_POST['name']; // vars from form
$myFile = "testFile.txt";

if (!isset($_POST['name'])) {
?>
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
    <input type="text" name="name" size="30"/>
    <input type="Submit" value="Submit">
</form>
<?php
}
else {
    $fh = fopen($myFile, 'w') or die("can't open file");
    $stringData = $name;
    fwrite($fh, $stringData);

    fclose($fh);
}
?>[/code]

The number is the text file changes so that is why I want to use it as a variable.  Currently the content of the text file is 10000

Here is the line of code that I need the variable to be placed in
[code]$t_current = isset($HTTP_GET_VARS['current']) ? $HTTP_GET_VARS['current'] : 0;[/code]
I need to replace $HTTP_GET_VARS['current'] : [b]0[/b] to a variable

Share this post


Link to post
Share on other sites
Use file_get_contents. [url=http://www.php.net/file_get_contents/]http://www.php.net/file_get_contents/[/url]

[code]
<?php

$t_current = file_get_contents($myFile);

?>
[/code]

Share this post


Link to post
Share on other sites

×

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.