Jump to content

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


AdRock

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
Link to comment
Share on other sites

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.