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!

     

Link to comment
Share on other sites

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

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.