Jump to content

Explode based on "\n"


fufaso

Recommended Posts

I'm hoping someone can shed a bit of light on what is wrong with my code here as I've been playing around with it for a few hours and haven't solved the riddle!

 

$fp=@fopen("test.txt","r") or die ("Cannot open the file, not there!");

while ($line=@fgets($fp, 1024)) {
$list = explode("\n", trim($line)); 
sort($list);
$count = count($list);
for($i=0;$i<$count;$i++){
print "<option>".$list[$i];
}}
@fclose($fp) or die ("Still open!!!");
?>
</select>
</form>

 

my text file looks like this

Canada
Brazil
US
Mexico

 

I'm trying to explode that text file into an array, sort it, and populate the options box. This isn't working, and all the different iterations I've tried are yielding no success either...  :-\

Link to comment
https://forums.phpfreaks.com/topic/221988-explode-based-on-n/
Share on other sites

ok, so I have it all working now, but I have one last question.

when I insert a new value and append it to my file, I am submitting back to the test.php page, however my new value is not being populated in the dropdown when i do that. I have to hit the reload button on the web browser to have it show up. Is there a way to have it repopulate when I hit submit??

Link to comment
https://forums.phpfreaks.com/topic/221988-explode-based-on-n/#findComment-1148708
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.