I have a piece of code that goes through a list of words and places the word in a specific file, depending on the first letter of the word. For example, if the first letter were "A," then the word would be placed within the A.txt file.
The problem is that output in the files is just a bunch of boxes, like the character encoding is somehow screwed up (which I don't understand how that could be possible). It's very strange. I can output the EXACT same info in an ECHO statement to the browser, and it appears just fine. I get no real errors.
Here's the PHP code (every bit of it):
$letters = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
foreach ($letters as $thisletter) {
$words = "";
foreach (explode("\r\n",file_get_contents("1.txt")) as $thisline) {
foreach (explode(" ",$thisline) as $thisword) {
if (trim($thisword) != "") {
if (substr($thisword,0,1) == $thisletter) {
$words = $words . "-" . $thisword;
}
}
}
}
file_put_contents($thisletter.".txt",$words);
}
Here's a small input sample file:
abaca abaci aback abaft abase abash abate abbas abbes abbey abbot abeam
abele abets abhor abide abler ables abode aboil abort about above abuse
boded bodes boffs bogan bogey boggy bogie bogle bogus bohea boils boing
bolas bolds boles bolls bolos bolts bolus bombe bombs bonds boned boner