newbie5050 Posted September 1, 2007 Share Posted September 1, 2007 hi guys, i have tried many different ways to do this and havent been getting anywhere, so any help will be much appreciated, i am simply reading text from a .txt file using the following code $search= $_POST["search"]; $file= $search . ".txt"; if(file_exists($file)){ $handle = fopen($search . ".txt", 'r'); $data = fread($handle, $file) or error("The file you requested is empty"); } else{ error ("The file you requested does not exist"); } and then just printing $data for the results, but the output doesnt present all of the information in the .txt, usualy just printing the first half. thanks in advance for any help!! Quote Link to comment https://forums.phpfreaks.com/topic/67515-reading-from-a-text-file/ Share on other sites More sharing options...
Fadion Posted September 1, 2007 Share Posted September 1, 2007 fread() takes the size to read as the second argument. U can either specify a hard coded filesize (ex. 4096) or preferably get the filesize of the actual file: fread($hande, filesize($file)); Quote Link to comment https://forums.phpfreaks.com/topic/67515-reading-from-a-text-file/#findComment-339009 Share on other sites More sharing options...
Barand Posted September 1, 2007 Share Posted September 1, 2007 try replacing $handle = fopen($search . ".txt", 'r'); $data = fread($handle, $file) or error("The file you requested is empty"); with $data = file_get_contents($file); Quote Link to comment https://forums.phpfreaks.com/topic/67515-reading-from-a-text-file/#findComment-339010 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.