mraza Posted January 30, 2010 Share Posted January 30, 2010 hi i wants to try a function but cant figured out how, it was task from my teacher, i wants to read a file which contains hyperlinks like this http://www.sote/floder http://www.mysite/html http://www.somesite/php http://www.mysite/12 http://www.msite/floder this will read the file and write them to other file with sorting a to z even numbers... means it will read the file and sort them and write a new file. thanks for any help Quote Link to comment https://forums.phpfreaks.com/topic/190410-need-to-write-a-file/ Share on other sites More sharing options...
premiso Posted January 30, 2010 Share Posted January 30, 2010 I will not provide the full answer / code as that is cheating imo. But you need to look into file sort fopen foreach fwrite and fclose. All will need to be used to do what you are tasked with. Quote Link to comment https://forums.phpfreaks.com/topic/190410-need-to-write-a-file/#findComment-1004434 Share on other sites More sharing options...
mraza Posted January 31, 2010 Author Share Posted January 31, 2010 thanks sir i will try that.. Quote Link to comment https://forums.phpfreaks.com/topic/190410-need-to-write-a-file/#findComment-1004437 Share on other sites More sharing options...
mraza Posted February 2, 2010 Author Share Posted February 2, 2010 please give me solution i am out now i have done so far read part, <?php $lines = file('links.txt'); sort($lines); foreach ($lines as $line_num => $line) { echo $line . "<br />\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/190410-need-to-write-a-file/#findComment-1005252 Share on other sites More sharing options...
premiso Posted February 2, 2010 Share Posted February 2, 2010 You are nearly there, you just need to fopen the links.txt file for writing (while truncating it) then inside the loop do an fwrite to write the lines to the file and finally before the ?> do an fclose on the links file. Quote Link to comment https://forums.phpfreaks.com/topic/190410-need-to-write-a-file/#findComment-1005254 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.