Jump to content


Photo

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


  • Please log in to reply
1 reply to this topic

#1 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 16 October 2006 - 09:12 PM

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
<?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);
}
?>

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
$t_current = isset($HTTP_GET_VARS['current']) ? $HTTP_GET_VARS['current'] : 0;
I need to replace $HTTP_GET_VARS['current'] : 0 to a variable
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#2 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 16 October 2006 - 09:20 PM

Use file_get_contents. http://www.php.net/file_get_contents/

<?php

$t_current = file_get_contents($myFile);

?>

SA PHP Archives - www.phparchives.za.org




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users