ICM Web Week 5: PHP Strings
October 11, 2009Heya there team,
So, I am unsure how to call up the last part of an array that I’ve placed in a text file.
The goal is to have the end-user input their zip code and then tell them what the what the temperature is going to be in their city.
I’ve got all the pages in order, per se.
http://davidphillips.us/icmweb/weather.html
which gets processed here:
http://davidphillips.us/icmweb/process_form.php
which goes into this text file:
http://davidphillips.us/icmweb/zipcode_data.txt
and can be seen here:
http://davidphillips.us/icmweb/display_comments.php
How can I get the last zip code to plug into this page:
http://davidphillips.us/icmweb/w5-php.php
Here’s the code:
<?
function myGrabs($stringStart) {
$zipCode = 10010;
$weather_source = “http://weather.yahooapis.com/forecastrss?p=” . $zipCode;
$weather_data = file_get_contents($weather_source);// $stringStart = “temp=\”";
$stringEnd = “\”";$startPos = strpos($weather_data,$stringStart);
$startPos += strlen($stringStart);
$endPos = strpos($weather_data,$stringEnd,$startPos);
$tempString = substr($weather_data,$startPos,$endPos-$startPos);
return($tempString); //this allows the future calls of the function to nab the result of the function.
}$myTemp = myGrabs(“temp=\”");
echo(“The weather is currently ” . $myTemp);
$myCity = myGrabs(“city=\”");
echo(“in the lovely and underappreciated city of ” . $myCity . “.”);
?>So, to sum up, I want to get the last placed array from the text file or from the first page, and plug it into the final page as the $zipCode.
All the pages are pretty in line with the notes code.
Preferrably, this could all be done in 2 steps and not 5 or whatever, but that’s beside the point.
I hope you are all having luck with your pages!
Sincerely,
David
This entry was posted in Comp Media for the Web. Bookmark the permalink. ← Stupid Pet Trick: The Zombie Alarm Clock Comm Lab – Sequential Art →