Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Collecting weather icon

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Collecting weather icon

Postby naustdal » Tue May 07, 2013 12:32 am

I'm struggling to get this code working.
It's basically should copy and paste an pictures and temperature from another page and past it into "yrdata.php"
Page: http://www.yr.no/sted/Norge/Sogn_og_Fjo ... liten.html

Code: Select all
<?php
// Collecting weather icon from YR.no
function put_yricon() {
$newstring = file_get_contents("http://www.yr.no/sted/Norge/Sogn_og_Fjordane/Eid/Nordfjordeid/ekstern_boks_liten.html"); // Recover the target webpage
$pos = strpos($newstring, '<img src="http://symbol.yr.no/grafikk/sym/b38/'); // Find the beginning tag of a specific element
$posout = strpos($newstring, '" alt="'); // Find the end tag of the specific element
$pos = $pos+10; // Start position
$result = substr($newstring, $pos, $posout-$pos); // Webpage + Start position + Endposition
echo "<a href=\"yrdata.php\"><img src=$result width=\"38\" height=\"38\"></a>";
}
// Collecting weather Temperature from YR.no
function put_yrtemp() {
$newstring1 = file_get_contents("http://www.yr.no/sted/Norge/Sogn_og_Fjordane/Eid/Nordfjordeid/ekstern_boks_liten.html"); // Recover the target webpage
$pos1 = strpos($newstring1, '<td class="'); // Find the beginning tag of a specific element
$posout1 = strpos($newstring1, '<td class="wind"'); // Find the end tag of the specific element
$pos1 = $pos1+126; // Start position
$result1 = substr($newstring1, $pos1, $posout1-$pos1); // Webpage + Start position + Endposition
echo "$result1";
}
?>

Yrdata.php have this line

Code: Select all
<?php include("php.php"); ?><?php if (function_exists('put_yricon')){put_yricon();} ?><?php if (function_exists('put_yrtemp')){put_yrtemp();} ?>
naustdal
New php-forum User
New php-forum User
 
Posts: 2
Joined: Tue May 07, 2013 12:24 am

Re: Collecting weather icon

Postby sandeep605085 » Tue May 07, 2013 10:08 pm

Hi,

Please check the site
http://www.yr.no/sted/Norge/Sogn_og_Fjordane/Eid/Nordfjordeid/ekstern_boks_liten.html

It does not contains <td class="wind" for which you are trying to get the string position from below line.
$posout1 = strpos($newstring1, '<td class="wind"'); // Find the end tag of the specific element .

so because of this it is not fetching the record as posout1 is blank.
may be you wanted to do '<td class="temperature"'

Thanks,
Sandeep Agrawal
Mindfire Solution.
User avatar
sandeep605085
New php-forum User
New php-forum User
 
Posts: 44
Joined: Tue Feb 26, 2013 6:00 am
Location: Mindfire Solutions


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.