Jump to content

[SOLVED] Text File


timmah1

Recommended Posts

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

Link to comment
Share on other sites

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)];

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.