mstevens Posted October 19, 2014 Share Posted October 19, 2014 I am trying to turn a .txt file into an array, count the items in the array, and display a random quote from it. <p class = "center"> <?php $Proverb = file('../proverbs.txt'); $ProverbCount = count($Proverb); echo rand(0, $ProverbCount-1); ?> <br> © 2014 </p> The issue I am having is that it states the file does not exist: FULL PATH: G:\EasyPHP-5.3.2i\www\PHP_Projects\ChineseZodiacs\Includes\inc_footer.php TEXT FILE: G:\EasyPHP-5.3.2i\www\PHP_Projects\ChineseZodiacs\proverbs.txt Please help, thank you. Quote Link to comment https://forums.phpfreaks.com/topic/291920-turning-a-txt-file-into-an-array/ Share on other sites More sharing options...
Psycho Posted October 19, 2014 Share Posted October 19, 2014 Um, copy the file to the location you are trying to access it? Quote Link to comment https://forums.phpfreaks.com/topic/291920-turning-a-txt-file-into-an-array/#findComment-1494136 Share on other sites More sharing options...
requinix Posted October 19, 2014 Share Posted October 19, 2014 Always use absolute paths. $Proverb = file($_SERVER['DOCUMENT_ROOT'] . '/proverbs.txt'); // might need /PHP_Projects/ChineseZodiacs in there too? Quote Link to comment https://forums.phpfreaks.com/topic/291920-turning-a-txt-file-into-an-array/#findComment-1494138 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.