timmah1 Posted December 15, 2007 Share Posted December 15, 2007 how do you format a text file to be read by php? I have a text file with random words "aureate"\n; "deism"\n; "ganger"\n; "graphoidea"\n; "imbecility"\n; "jollity"\n; "keenness"\n; "lipotype"\n; "nimiety"\n; "oldwomanish"\n; "purveyance"\n; "refocillation"\n; "scaphoid"\n; "sententious"\n; "tumefying"\n; "unforbidden"\n; "unmade"\n; "unretracted"\n; "withers"\n; "wittiness"\n; "antevert"\n; "beetlehead"\n; "better"\n; "brickcolored"\n; "chastened"\n; "divers"\n; "extenuated"\n; "funicular"\n; "miserly"\n; "potluck"\n; "prodromous"\n; "rappee"\n; "scintilla"\n; "serosity"\n; "subjugate"\n; "superexcellence"\n; "tippet"\n; "trituration"\n; "unculpable"\n; "untired"\n; I have a script that is suppose to pull only one of those words out, but the problem is, it's pulling all of them out. Here is my php script $filename = "./random.txt"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); $words = explode("\r", $contents); $temp_pass = $words[rand(0, count($words)-1)]; Any idea what I'm doing wrong? Thanks is advance Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted December 15, 2007 Share Posted December 15, 2007 in your explode() function you are telling it to look for /r when it should be looking for \n Quote Link to comment Share on other sites More sharing options...
timmah1 Posted December 15, 2007 Author Share Posted December 15, 2007 Thank you That fixed it. But now what's being show is this "serosity"\n; Instead of just the word. Do I need to take out the " in the txt file? Quote Link to comment Share on other sites More sharing options...
timmah1 Posted December 15, 2007 Author Share Posted December 15, 2007 Nevermind, got it fixed. Thank you for your help, it's really appreciated. Quote Link to comment Share on other sites More sharing options...
trq Posted December 15, 2007 Share Posted December 15, 2007 Is that exactly what your text file looks like? Can you change the format so it is simply each word on a seperate line? They do not need quotes or \n chars. ps: Code wise, I would simply use... <?php $words = file('./randomtext.txt'); $temp_pass = $words[rand(0,count($words)-1)]; ?> Quote Link to comment Share on other sites More sharing options...
timmah1 Posted December 15, 2007 Author Share Posted December 15, 2007 That is much simpler, thank you thorpe! 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.