Mike D Posted December 22, 2011 Share Posted December 22, 2011 So, I'm trying to get this read my text document "news.txt" and display the contents. My code: div.newscontent{ padding:0px; margin-top:60px; margin-bottom:0px; margin-left:400px; margin-right:0px; position:absolute; width:457px; height:330px; text-align:center; color:#FFFFFF; } <div class='newscontent'> <?PHP $filename = "news.txt"; $arr = file($filename); foreach($arr as $line){ print $line . "<br/>"; } ?> </div> This is the output I get: "; } ?> Whats wrong? Link to comment https://forums.phpfreaks.com/topic/253641-reading-a-text-file-and-displaying-its-contents/ Share on other sites More sharing options...
scootstah Posted December 22, 2011 Share Posted December 22, 2011 file_get_contents() Link to comment https://forums.phpfreaks.com/topic/253641-reading-a-text-file-and-displaying-its-contents/#findComment-1300307 Share on other sites More sharing options...
requinix Posted December 22, 2011 Share Posted December 22, 2011 Either your file is not named *.php or PHP is not installed/installed properly. Link to comment https://forums.phpfreaks.com/topic/253641-reading-a-text-file-and-displaying-its-contents/#findComment-1300312 Share on other sites More sharing options...
scootstah Posted December 22, 2011 Share Posted December 22, 2011 Either your file is not named *.php or PHP is not installed/installed properly. How did you come to that conclusion? Link to comment https://forums.phpfreaks.com/topic/253641-reading-a-text-file-and-displaying-its-contents/#findComment-1300314 Share on other sites More sharing options...
Mike D Posted December 22, 2011 Author Share Posted December 22, 2011 Awww fuck me.. Sorry guys my bad. It did work all the time, but the files wasnt on my xamp folder... Topic solved, sorry for spam E: just got one question, how I can read and display the time when the file was edited last time? Link to comment https://forums.phpfreaks.com/topic/253641-reading-a-text-file-and-displaying-its-contents/#findComment-1300320 Share on other sites More sharing options...
Pikachu2000 Posted December 22, 2011 Share Posted December 22, 2011 filemtime, I believe. Link to comment https://forums.phpfreaks.com/topic/253641-reading-a-text-file-and-displaying-its-contents/#findComment-1300329 Share on other sites More sharing options...
requinix Posted December 22, 2011 Share Posted December 22, 2011 Either your file is not named *.php or PHP is not installed/installed properly. How did you come to that conclusion? Experience, and from having seen many of these questions in my time. Look at the code as HTML markup, not PHP code: the <?php is the beginning of a tag which doesn't end until the next />. The following "; } ?> will be rendered as text - precisely as OP described. Link to comment https://forums.phpfreaks.com/topic/253641-reading-a-text-file-and-displaying-its-contents/#findComment-1300676 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.