freeloader Posted October 7, 2006 Share Posted October 7, 2006 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: xxxxvariable 2: xxxxendI want it to be:variable 1: xxxxx variable 2: xxxxx endthanks in advance Link to comment https://forums.phpfreaks.com/topic/23279-remove-line-break/ Share on other sites More sharing options...
Orio Posted October 7, 2006 Share Posted October 7, 2006 You can add before outputing them-$breaks=array("\n", "\r");$var1=str_replace($breaks, "", $var1);$var2=str_replace($breaks, "", $var2);Orio. Link to comment https://forums.phpfreaks.com/topic/23279-remove-line-break/#findComment-105529 Share on other sites More sharing options...
freeloader Posted October 7, 2006 Author Share Posted October 7, 2006 Strange, I already tried str_replace and it didn't work before, probably made some nooby mistake. Thanks for the solution, you can close this topic :) Link to comment https://forums.phpfreaks.com/topic/23279-remove-line-break/#findComment-105536 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.