JAMBO Posted August 21, 2007 Share Posted August 21, 2007 Forgive me if this is a stupid question, since I am a PHP noobie. I am one who likes to figure things out on my own but...this one has me stumped. $fcontents = file ('WUNDERGRUNDstnlist.txt'); //reads file into an array for ($i = 0; $i !== count($fcontents); $i++) { $StationID = $fcontents[$i]; $off_site = "http://www.wunderground.com/history/airport/".$StationID."/".$year."/".$month."/".$date."/DailyHistory.html?req_city=NA&req_state=NA&req_statename=NA&MR=1"; echo $off_site; } Outputs the following... http://www.wunderground.com/history/airport/CWIJ /2007/8/11/DailyHistory.html?req_city=NA&req_state=NA&req_statename=NA&MR=1http://www.wunderground.com/history/airport/CWOB /2007/8/11/DailyHistory.html?req_city=NA&req_state=NA&req_statename=NA&MR=1http://www.wunderground.com/history/airport/71910 /2007/8/11/DailyHistory.html?req_city=NA&req_state=NA&req_statename=NA&MR=1http://www.wunderground.com/history/airport/71094 /2007/8/11/DailyHistory.html?req_city=NA&req_state=NA&req_statename=NA&MR=1http://www.wunderground.com/history/airport/71093 /2007/8/11/DailyHistory.html?req_city=NA&req_state=NA&req_statename=NA&MR=1http://www.wunderground.com/history/airport/CWPX /2007/8/11/DailyHistory.html?req_city=NA&req_state=NA&req_statename=NA&MR=1http://www.wunderground.com/history/airport/71090 /2007/8/11/DailyHistory.html?req_city=NA&req_state=NA&req_statename=NA&MR=1http://www.wunderground.com/history/airport/CWYM /2007/8/11/DailyHistory.html?req_city=NA&req_state=NA&req_statename=NA&MR=1http://www.wunderground.com/history/airport/71081/2007/8/11/DailyHistory.html?req_city=NA&req_state=NA&req_statename=NA&MR=1 If am interpreting the output correctly, the iteration of the for-loop goes back to the start as soon as it hits the $StationId variable. And there in lies the problem. I need the $off_site variable, after one iteration, to represent the entire URL and not just half of it or a combination of the lasthalf and the beginning half. (ie: "http://www.wunderground.com/history/airport/".$StationID."/".$year."/".$month."/".$date."/DailyHistory.html?req_city=NA&req_state=NA&req_statename=NA&MR=1" Any help would be appreciated. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/65912-an-issue-with-sting-catenation-within-a-for-loop/ Share on other sites More sharing options...
zq29 Posted August 21, 2007 Share Posted August 21, 2007 I'm not sure I totaly follow what you're saying in your problem description - Are you saying that there appears to be a newline character in your$StationID variable? Does this fix your issue? <?php $fcontents = file ('WUNDERGRUNDstnlist.txt'); for($i=0; $i < count($fcontents); $i++) { $StationID = str_replace(array("\r","\n"),"",$fcontents[$i]); $off_site = "http://www.wunderground.com/history/airport/$StationID/$year/$month/$date/". "DailyHistory.html?req_city=NA&req_state=NA&req_statename=NA&MR=1\r\n"; echo $off_site; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/65912-an-issue-with-sting-catenation-within-a-for-loop/#findComment-329894 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.