Log in

View Full Version : Modify this PHP script to style portion differently?



pxlcreations
01-25-2011, 09:35 PM
Hey all, I have a question about this script I am using to display weather on my site through yahoo rss. This is the script that pulls it all in:


<?php
/*
Credits: Bit Repository
URL: http://www.bitrepository.com/web-programming/ajax/show-yahoo-weather.html
*/

error_reporting (E_ALL ^ E_NOTICE);

if(isSet($_GET['p'])) // at least 'p' is required
{
$p = $_GET['p'];

$u = isSet($_GET['u']) ? $_GET['u'] : '';

require('magpierss/rss_fetch.inc');

$url = 'http://xml.weather.yahoo.com/forecastrss/'.$p.'&u='.$u. '.xml';

$rss = fetch_rss($url);

$title = $rss->items[0]['title'];

$description = $rss->items[0]['description'];

echo "<br />".$title."<br /><br />".$description."<br />";
}
?>

It then displays the information as this:


Conditions for Buffalo, NY at 3:56 pm EST

[WEATHER IMAGE]

Current Conditions:
Light Snow, 30 F

Forecast:
Tue - Few Snow Showers. High: 32 Low: 20
Wed - Mostly Cloudy. High: 27 Low: 21
Thu - Few Snow Showers. High: 24 Low: 19
Fri - Snow Showers. High: 25 Low: 20
Sat - Snow Showers. High: 29 Low: 20

Would there be any way to display the Tue - Few Snow Showers. High: 32 Low: 20 in a div? Like <div class="future">Tue - Few Snow Showers. High: 32 Low: 20</div>? Let me know if this can be done, thank you.

fastsol1
01-26-2011, 12:10 AM
You're already echoing the info out, all you need to do is add the div tags inside the echo.

/*
Credits: Bit Repository
URL: http://www.bitrepository.com/web-programming/ajax/show-yahoo-weather.html
*/

error_reporting (E_ALL ^ E_NOTICE);

if(isSet($_GET['p'])) // at least 'p' is required
{
$p = $_GET['p'];

$u = isSet($_GET['u']) ? $_GET['u'] : '';

require('magpierss/rss_fetch.inc');

$url = 'http://xml.weather.yahoo.com/forecastrss/'.$p.'&u='.$u. '.xml';

$rss = fetch_rss($url);

$title = $rss->items[0]['title'];

$description = $rss->items[0]['description'];

echo "<div class=\"future\"><br />$title<br /><br />$description<br /></div>";
}
There's no need to concatenate all that together either, just keep it simpler like I show.

pxlcreations
01-26-2011, 12:14 AM
No because that would be adding a div to the entire content. I want to just add divs to these lines:


Tue - Few Snow Showers. High: 32 Low: 20
Wed - Mostly Cloudy. High: 27 Low: 21

so it would come out as:


<div class="future">Tue - Few Snow Showers. High: 32 Low: 20</div>
<div class="future">Wed - Mostly Cloudy. High: 27 Low: 21</div>

fastsol1
01-26-2011, 01:57 AM
Is the $description a string with all the days in it? If so the n you would have to use something like strpos() or a regex to find the days within the string and then manipulate it from there.

pxlcreations
01-26-2011, 02:24 AM
Is the $description a string with all the days in it? If so the n you would have to use something like strpos() or a regex to find the days within the string and then manipulate it from there.

I'm not sure how to do this, do you have an example?

pxlcreations
01-26-2011, 09:57 PM
Any other ideas? I would like to get this done soon..