KingOfHeart Posted October 24, 2010 Share Posted October 24, 2010 I got this script to replace all the lines with a * to a name. It looks like it works but there's no line breaks when it outputs. <? $fp = fopen("temp.txt", "r"); $buffer = fread($fp, 120000); fclose($fp); $lines = explode("\n", $buffer); $t = 1; $n = 0; while($n < 939) { if(substr($lines[$n],0,1) == "*") { $lines[$n] = "o_tile1" . $t . "\n"; $t++; //echo $lines[$n]; } $n++; } //return; $fp = fopen("temp.txt", "w"); $buffer = implode("\n", $lines)."\n"; fwrite($fp, $buffer); fclose($fp); ?> What did I do wrong? Link to comment https://forums.phpfreaks.com/topic/216738-almost-got-it/ Share on other sites More sharing options...
revraz Posted October 25, 2010 Share Posted October 25, 2010 Did you try \n \r ? Link to comment https://forums.phpfreaks.com/topic/216738-almost-got-it/#findComment-1126023 Share on other sites More sharing options...
KingOfHeart Posted October 25, 2010 Author Share Posted October 25, 2010 Finally got the right combo. <? $fp = fopen("temp.txt", "r"); $buffer = fread($fp, 120000); fclose($fp); $lines = explode("\r\n", $buffer); $t = 1; $n = 0; while($n < 939) { if(substr($lines[$n],0,1) == "*") { $lines[$n] = "o_tile1" . $t; $t++; //echo $lines[$n]; } $n++; } //return; $fp = fopen("temp.txt", "w"); $buffer = implode("\r\n", $lines); fwrite($fp, $buffer); fclose($fp); ?> Link to comment https://forums.phpfreaks.com/topic/216738-almost-got-it/#findComment-1126065 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.