jamesxg1 Posted July 16, 2009 Share Posted July 16, 2009 Ok this is my script, <?php $textfile = 'datafiles.txt'; $handle = fopen("$textfile", "r"); $contents = fread($handle, filesize($textfile)); list($filename, $size) = split(" - ", $contents); fclose($handle); print $filename . " - " . $size . PHP_EOL . "<br>"; ?> This is the 'datafiles.txt' file contents, test.php - 153 write.php - 202 but when i run the script all i get is this, test.php - 153 write.php ^^ that's one line ^^ i am very confused , does anyone have any ideas to why ?, Many thanks, James. Quote Link to comment https://forums.phpfreaks.com/topic/166200-solved-get-file-contents-and-splitting-problem/ Share on other sites More sharing options...
Alex Posted July 16, 2009 Share Posted July 16, 2009 Well, what's your expected output? Telling us that would help explain how to get what you want. To answer you question directly your problem is that your variable $size contains "153 write.php". So you're calling the PHP_EOL/<br> after everything. Quote Link to comment https://forums.phpfreaks.com/topic/166200-solved-get-file-contents-and-splitting-problem/#findComment-876400 Share on other sites More sharing options...
jamesxg1 Posted July 16, 2009 Author Share Posted July 16, 2009 Well, what's your expected output? Telling us that would help explain how to get what you want. To answer you question directly your problem is that your variable $size contains "153 write.php". So you're calling the PHP_EOL/<br> after everything. Ok, well basically what i need is an output like this, FILENAME - FILESIZE FILENAME - FILESIZE if you get what i mean , but i really dont understand how to do this, this is my first time with php file system functions . Quote Link to comment https://forums.phpfreaks.com/topic/166200-solved-get-file-contents-and-splitting-problem/#findComment-876402 Share on other sites More sharing options...
Alex Posted July 16, 2009 Share Posted July 16, 2009 Well, what's your expected output? Telling us that would help explain how to get what you want. To answer you question directly your problem is that your variable $size contains "153 write.php". So you're calling the PHP_EOL/<br> after everything. Ok, well basically what i need is an output like this, FILENAME - FILESIZE FILENAME - FILESIZE if you get what i mean , but i really dont understand how to do this, this is my first time with php file system functions . Is the number next to it in the file the "FILESIZE" that you want outputted? Or do you want it recalculated? Quote Link to comment https://forums.phpfreaks.com/topic/166200-solved-get-file-contents-and-splitting-problem/#findComment-876407 Share on other sites More sharing options...
jamesxg1 Posted July 16, 2009 Author Share Posted July 16, 2009 Well, what's your expected output? Telling us that would help explain how to get what you want. To answer you question directly your problem is that your variable $size contains "153 write.php". So you're calling the PHP_EOL/<br> after everything. Ok, well basically what i need is an output like this, FILENAME - FILESIZE FILENAME - FILESIZE if you get what i mean , but i really dont understand how to do this, this is my first time with php file system functions . Is the number next to it in the file the "FILESIZE" that you want outputted? Or do you want it recalculated? Its already on the text file ill attach it [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/166200-solved-get-file-contents-and-splitting-problem/#findComment-876409 Share on other sites More sharing options...
Alex Posted July 16, 2009 Share Posted July 16, 2009 If it's already in the text file then it sounds like you want to output the exact contents of the file? <?php $textfile = 'datafiles.txt'; $handle = fopen("$textfile", "r"); $contents = fread($handle, filesize($textfile)); fclose($handle); echo nl2br($contents); Or am I wrong? Quote Link to comment https://forums.phpfreaks.com/topic/166200-solved-get-file-contents-and-splitting-problem/#findComment-876413 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.