csckid Posted November 24, 2009 Share Posted November 24, 2009 I wrote a code to read txt file. In text file there are large space, but my php code avoid this space. How do I fix this? mydata.txt 1. myname 12 23 2. myname2 34 42 thanks Quote Link to comment https://forums.phpfreaks.com/topic/182809-reading-file/ Share on other sites More sharing options...
wildteen88 Posted November 24, 2009 Share Posted November 24, 2009 Post the code you're having issues with here. We'll be able to help you further. Quote Link to comment https://forums.phpfreaks.com/topic/182809-reading-file/#findComment-964874 Share on other sites More sharing options...
csckid Posted November 24, 2009 Author Share Posted November 24, 2009 <html> <body> <?php $file = fopen("mydata.txt", "r"); while (!feof($file)) { $data = fgets($file); echo $data."<br>"; } fclose($file); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/182809-reading-file/#findComment-964880 Share on other sites More sharing options...
wildteen88 Posted November 24, 2009 Share Posted November 24, 2009 That code is fine. It will display the contents of the file being read. What issue are you having with that code? Quote Link to comment https://forums.phpfreaks.com/topic/182809-reading-file/#findComment-964900 Share on other sites More sharing options...
Cardale Posted November 24, 2009 Share Posted November 24, 2009 I believe there is a command to "not" remove spaces? I just can't remember I will look. Quote Link to comment https://forums.phpfreaks.com/topic/182809-reading-file/#findComment-964903 Share on other sites More sharing options...
csckid Posted November 24, 2009 Author Share Posted November 24, 2009 it prints 1. myname 12 23 2. myname2 34 42 I want it to print like this 1. myname 12 23 2. myname2 34 42 Quote Link to comment https://forums.phpfreaks.com/topic/182809-reading-file/#findComment-964905 Share on other sites More sharing options...
wildteen88 Posted November 24, 2009 Share Posted November 24, 2009 Change your code to $contents = file_get_contents('mydata.txt'); echo '<pre>' . $contents . '</pre>'; The reason why your spaces are not showing is because web browsers ignore any whitespace. I added the pre tags which forces the browser to display the spaces. Quote Link to comment https://forums.phpfreaks.com/topic/182809-reading-file/#findComment-964911 Share on other sites More sharing options...
csckid Posted November 24, 2009 Author Share Posted November 24, 2009 thanks.. can you give me an idea..... I am actually reading a large file and inserting the content in database the file looks like this 1. myname 12 23 2. myname2 42 3. myname3 14 34 4. myname4 21 In 2nd and 4th row one of the content is not present. How will I detect that? Quote Link to comment https://forums.phpfreaks.com/topic/182809-reading-file/#findComment-964922 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.