Jump to content

Remove line break


freeloader

Recommended Posts

Hi guys,

I'm writing a script that opens a file, gets the line, stores it as a variable, does the same for another file and uses them in a function. All this goes well, but when reading the line from the file, php adds a line break at the end of my variable. I tried doing streplace for \n and \r but it keeps giving the same result.

[code] $array1 = explode("\n", file_get_contents("file1.txt"));
$array2 = explode("\n", file_get_contents("file2.txt"));
$count = count($array1); 
for ($i = 0; $i < $count; $i++) 

  my_function($array1[$i],$array2[$i]); 
}

my_function($var1,$var2){
echo "variable 1: $var1 varible 2: $var2 end";
}
[/code]

The output of this code is:

variable 1: xxxx
variable 2: xxxx
end

I want it to be:

variable 1: xxxxx variable 2: xxxxx end

thanks in advance
Link to comment
https://forums.phpfreaks.com/topic/23279-remove-line-break/
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.