Results 1 to 6 of 6

Thread: Modify this PHP script to style portion differently?

  1. #1
    Join Date
    Apr 2010
    Posts
    89
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Modify this PHP script to style portion differently?

    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 Code:
    <?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.

  2. #2
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    You're already echoing the info out, all you need to do is add the div tags inside the echo.
    PHP Code:
    /*
    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.

  3. #3
    Join Date
    Apr 2010
    Posts
    89
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default

    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:

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

  4. #4
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    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.

  5. #5
    Join Date
    Apr 2010
    Posts
    89
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by fastsol1 View Post
    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?

  6. #6
    Join Date
    Apr 2010
    Posts
    89
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default

    Any other ideas? I would like to get this done soon..

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •