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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.