Jump to content

An issue with sting catenation within a for-loop.


JAMBO

Recommended Posts

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!

     

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;
}
?>

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.