Jump to content

almost got it


KingOfHeart

Recommended Posts

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

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

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.