SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy A difficult replacement task

    Hello!

    I am running a livescore, which is updating from outside. The problem is, that all the start hours of the matches are depending on the time zone of the country they are being played in. For example:
    All England matches start at 15:00 PM UK time, All Spanish matches start at 17:00 spanish time.
    What I want, is to get all times in the timezone of my country. That means, that I have to shift all hours in different way, depending on their nationality. For example, I have to put all the english matches start times plus 2 hours, and all the spanish plus one hour.
    The problem is, that as I mentioned above, the livescore is updating from outside, and I have no idea of the structure of its code. All I have is echo $html; and that $html contains everything - the countries, the matches, the results, the times etc. So, the only thing I am able to do is to make some replacements, and here goes the whole problem, because I don't know how to describe them.

    The html code of the area with the times looks like this:

    <tr bgcolor="#82FC74"><td class="title" colspan="4" height="18">&nbsp;<b>England</b> - Premiership</td></tr>
    <tr bgcolor="#82FC74"><td class="match-light" width="45" height="18">&nbsp;10:35</td><td class="match-light" align="right" width="286" colspan="3">September 13&nbsp;</td></tr>
    <tr><td colspan="4" height="1"></td></tr><tr bgcolor="#cfcfcf"><td width="45" height="18">&nbsp;21:15</td><td align="right" width="118">Chelsea</td><td align="center" width="50">? - ?</td><td width="118">Liverpool</td></tr><tr><td colspan="4" height="1"></td></tr><tr bgcolor="#FFFFFF"><td colspan="4" height="4"></td></tr><tr><td colspan="4" height="1"></td></tr>

    The onliest idea I am up to is to describe a function approximately with the following content:

    function settimes() {
    if (text in the <td tag with class="title"> contains the word "England") {
    shift the hours in the next <td tag with class="match-light"> plus 2 hours;
    shift the hours in all following <td tags without defined class> plus 2 hours until the next <td tag with class="title">;
    }
    if (text in the <td tag with class="title"> contains the word "Spain") {
    shift the hours in the next <td tag with class="match-light"> plus 1 hour;
    shift the hours in all following <td tags without defined class> plus 1 hour until the next <td tag with class="title">;
    }
    }

    I know how to shift the hours, that's an easy task, but what I don't know is how to describe this function in PHP. Do you have any ideas how can I do it? I know it is possible, because there are other websites, using the same script as me, which have set their times.


    I hope there is somebody to help me, because I even don't know where to start from.

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Does this come in chunks with one country or mixed. If only one then something along the lines to find the country:
    Code php:
    preg_match('#<td class="title" colspan="4" height="18">&nbsp;<b>(.+?)</b>#i', $html, $matches);
     
    $country = $matches[1];

    And to replace the times:

    Code php:
    $newhtml = preg_replace_callback('#<td width="45" height="18">&nbsp;([0-9:]+)</td>#i',$html,'replace_times');
     
    $offset=2;
     
    function replace_times($matches){
      global $offset;
      $time=strtotime($matches[1])+$offset*3600;
      return '<td width="45" height="18">&nbsp;'.strftime('%H:%M',$time).'</td>';
    }


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
  •