AdRock Posted October 16, 2006 Share Posted October 16, 2006 I have a text file which basically holds a numberI would like to use that number to be a variable but am having trouble getting it to workhere 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 10000Here 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 https://forums.phpfreaks.com/topic/24143-how-do-get-contents-of-a-text-file-into-a-variable-resolved/ Share on other sites More sharing options...
xsist10 Posted October 16, 2006 Share Posted October 16, 2006 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] Link to comment https://forums.phpfreaks.com/topic/24143-how-do-get-contents-of-a-text-file-into-a-variable-resolved/#findComment-109734 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.