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
https://forums.phpfreaks.com/topic/81781-solved-text-file/
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
https://forums.phpfreaks.com/topic/81781-solved-text-file/#findComment-415492
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.