matthew9090 Posted April 3, 2011 Share Posted April 3, 2011 I have this code so far: $file = fopen("file.txt", "r"); while(!feof($file)) { echo "<a href=" . fgets($file). ">" . fgets($file) . "</a><br />"; } fclose($file); but if i use fgets twice (like above) it makes the link, link to the previous result Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 3, 2011 Share Posted April 3, 2011 What does the content of the file look like? Ken Quote Link to comment Share on other sites More sharing options...
matthew9090 Posted April 3, 2011 Author Share Posted April 3, 2011 http://website1.com http://website2.com ..... Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 3, 2011 Share Posted April 3, 2011 Try: <?php $sites = array_map('trim',file('file.txt')); //read the whole file into an array & trim the newline character from the end of each line foreach ($sites as $link) { echo "<a href='$link'>$link</a><br />"; } ?> Ken Quote Link to comment Share on other sites More sharing options...
matthew9090 Posted April 3, 2011 Author Share Posted April 3, 2011 thanks ken Quote Link to comment Share on other sites More sharing options...
dcro2 Posted April 3, 2011 Share Posted April 3, 2011 If you have PHP5, you might as well just use the FILE_IGNORE_NEW_LINES flag of file. It might not make any difference if the file is small but, I don't know, I like cleaner code . $sites = file('file.txt', FILE_IGNORE_NEW_LINES); Quote Link to comment 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.