firemike Posted May 10, 2007 Share Posted May 10, 2007 Weird issue I'm having here. I hope someone has answers I'm reading from a text file 'servernames.txt' which looks like: server1 server2 server3 I'm reading the files into a var:, then exploding into an array: $servernames=file_get_contents("http://servernames.txt"); $server_array=explode("\n",$servernames); A print_r shows exactly what I want: print_r($server_array); Array ( [0] => server1 [1] => server2 [2] => server3 ) Then I start the foreach function, the weirdness starts here. foreach ($server_array as $server) { $search=file_get_contents("http://webaddress/page.php?server=$server"); } now if I echo $server within the foreach, I get the correct result. However when I put it onto my file_get_contents the server outputs to "server1_" and not "server1". This happens to server1 and server2, but not the last entry in the textfile server3. Server 3 works. Now I have tried to change the text file to a space delimiter, changing the explode: server1 server2 server3 And it works fine, it's only adding the "server1_" when the textfile is exploding into a newline. Am I missing a step? I would prefer to add each entry on a new line but I don't understand why I am getting these added underscores. Thanks for reading, Mike Link to comment https://forums.phpfreaks.com/topic/50737-foreach-array-adding-_-to-values/ Share on other sites More sharing options...
firemike Posted May 10, 2007 Author Share Posted May 10, 2007 Ahh, it must have been converting some whitespace to an "_". A $server=trim($server); fixed it. Link to comment https://forums.phpfreaks.com/topic/50737-foreach-array-adding-_-to-values/#findComment-249441 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.