FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


[Resolved] Good 'Ol Fwrite - Losing txt formatting





Aredon
At the moment a friend and I are working on a project to make things in our guild run smoother. The plan is to write an addon to handle a list in-game. We'd like to pull data from the website into a textfile and then convert the textfile to an lua file after it's downloaded. However, the issue we've run into now is if someone saves the textfile to their computer (as intended) we lose part of the formatting (the returns). This wouldn't be an issue, but lua formatting is going to require that the first line be separated from the rest. When viewed in the browser the textfile appears to be formatted fine, but when downloaded all the returns vanish. Is there another way I could be writing this where the returns will stay when downloaded?
Code:
$list="prioritylist.txt";
$fh=fopen($list, 'w') or die("can't open file");
$stringData="local HALootManager = HALootManager;
\nHALootManager.PriorityList = {
Mains = {\n"; // START MAIN CHARACTERS
fwrite($fh, $stringData);
$maincounter=1;
while($maincounter<=10){
$stringData="[".$maincounter."]=\"Charname\",\n";
fwrite($fh, $stringData);
$maincounter=$maincounter+1;
}
$stringData="},
PrimaryAlts = {\n";
fwrite($fh, $stringData); // END MAIN CHARACTERS, START PRIMARY ALTS
$pacounter=1;
while($pacounter<=10){
$stringData="[".$pacounter."]=\"Charname\",\n";
fwrite($fh, $stringData);
$pacounter=$pacounter+1;
}
$stringData="},
Alts = {\n";
fwrite($fh, $stringData); // END PRIMARY ALTS, START ALTS
$altcounter=1;
while($altcounter<=10){
$stringData="[".$altcounter."]=\"Charname\",\n";
fwrite($fh, $stringData);
$altcounter=$altcounter+1;
}
$stringData="},\n}";
fwrite($fh, $stringData); // END ALTS, END FILE
fclose($fh);



This should yield in lua format:


Code:

local HALootManager = HALootManager;

HALootManager.PriorityList = {
Mains = {
[1]="Charname",
[2]="Charname",
[3]="Charname",
[4]="Charname",
[5]="Charname",
[6]="Charname",
[7]="Charname",
[8]="Charname",
[9]="Charname",
[10]="Charname",
},
PrimaryAlts = {
[1]="Charname",
[2]="Charname",
[3]="Charname",
[4]="Charname",
[5]="Charname",
[6]="Charname",
[7]="Charname",
[8]="Charname",
[9]="Charname",
[10]="Charname",
},
Alts = {
[1]="Charname",
[2]="Charname",
[3]="Charname",
[4]="Charname",
[5]="Charname",
[6]="Charname",
[7]="Charname",
[8]="Charname",
[9]="Charname",
[10]="Charname",
},
}


but we end up with all the returns removed :/
Aredon
upon further investigation it appears formating was only lost in notepad on the download... Not really sure why, but in any case this thread can be closed.
imagefree
i thunk u should use \r\n instead of \n.

\r\n is windows compatible.
However browser and php can work with both type of end line characters.
rvec
use notepad++ or wordpad instead of notepad.
notepad works with /r/n
notepad++ can work with /n, /r and /r/n and can convert between them
wordpad can at least work with /r/n and /n I don't think it can convert and I don't know if it works with /r
Aredon
rvec wrote:
use notepad++ or wordpad instead of notepad.
notepad works with /r/n
notepad++ can work with /n, /r and /r/n and can convert between them
wordpad can at least work with /r/n and /n I don't think it can convert and I don't know if it works with /r

Yeah we ended up figuring out that the lua file would load fine in the game's addon folder. So no changes to the code needed Very Happy. Thanks for the quick responses guys but we troubleshooted out before then.
Related topics
PHP Write to line
Question about MySQL!
visit counting *php*
Hibernation problem
Robots.txt
The degradation of language in general.
Change or is it just me?
importing a .txt
PHP: Writing to txt file
Images / Formatting to the top of the page *Resolved*
Open, Write to and Close a txt file using php
I need a site that can handle submisions! help!
How to prepare a "robots.txt" to get crawled by Se
help - trouble getting operators to work with fwrite
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.