SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2001
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    counting in a script

    I would like to ask you if you could help me with this script. I want to have a count in it that it will take not one but 10 news lines.

    I hope to hear from you soon


    <?php
    echo "<B>FinancieŽl dagblad</B><BR><table><tr><td>";
    if(!($myFile=fopen("http://hfd.bvdep.com/Nieuwsdienst.asp","r")))
    {
    echo "The news interface is down for maintenance.";
    exit;
    }
    while(!feof($myFile))
    {
    $myLine.=fgets($myFile,256);
    }
    fclose($myFile);
    $start='<tr><td class="tekstregulargrey">';
    $end='</a></td></tr>';
    $start_position=strpos($myLine, $start);
    $end_position=strpos($myLine, $end)+strlen($end);
    $length=$end_position-$start_position;
    $myLine=substr($myLine, $start_position, $length);
    echo $myLine;
    echo "</tr></table></font>";
    ?>

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, if I understand what you are trying to do, a better function to use is the file() function. This will open a file read in its contents and assign each line in the file as an element of an array. Then closes the file. All in the one function. Neat eh?

    Then you can loop through the array and print out the first ten lines in your file:
    PHP Code:
    $fileArray file("http://hfd.bvdep.com/Nieuwsdienst.asp");

    for ( 
    $i 0$i 10$i++ ) {
       echo 
    $fileArray[$i];

    Is this along the lines of what you want to do?

    <<edited>>
    Actually, I think I understand better what you want to do. you only want to print out the first 10 rows of the table that is embedded in the HTML in that file right? Well this code assumes that within that file each table row is on a seperate line:
    PHP Code:
    $fileArray file("http://hfd.bvdep.com/Nieuwsdienst.asp");
    $searchStr ='<tr><td class="tekstregulargrey">';
    $i 0;
    foreach(
    $fileArray AS $line) {
       if ( 
    strstr($line$searchStr) ) {
          echo 
    $line;
          
    $i++;
       }
       if ( $ == 
    10 ) {
          break;
       }

    Last edited by freakysid; Jun 29, 2001 at 16:56.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2001
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry where do I have to past your script into my script???
    Thanks in advance.
    The script above can be seen at http://sander.landzaat.com/dirk/php/download.php
    I jut started with php. But I want the server to download the newslines in a file and when someone is opening my homepage it will automatically take the newest 10 news urls from that file to the website.
    I know not even that but of php I just started with it because I knew I could do this with php. So step to step please.
    Last edited by dijksma; Jun 30, 2001 at 03:44.

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is a complete test script that demonstrates what I had in mind. Naturally, you would want to customise the html further.
    PHP Code:
    <html><head><title>Leach Test</title></head>
    <body>
    <B>Financieel dagblad</B><BR>
    <table>
    <?php
    $fileArray 
    file("http://hfd.bvdep.com/Nieuwsdienst.asp");

    if ( ! 
    $fileArray ) {
       echo 
    '<tr><td>The news interface is down for maintenance.</td></tr>',
            
    '</table></body></html>';
       break;
    }   

    $searchStr ='<td class="tekstregulargrey">';
    $i 0;
    foreach(
    $fileArray AS $line) {
       if ( 
    strstr($line$searchStr) ) {
          echo 
    $line"\n";
          
    $i++;
       }
       if ( 
    $i == 10 ) {
          break;
       }
    }
    ?>
    </table>
    </body></html>

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2001
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    TX it works great but how when you click on the deeplink the file goes to
    http://sander.landzaat.com/dirk/ShowNews.asp*.........*
    but it has to go to
    http://hfd.bvdep.com/ShowNews.asp*............*
    How do I put this in the script

    But thanks again for your time.

  6. #6
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, they appear to be using relative links in their html. So you would need to add this line:
    $line = str_replace("ShowNews.asp?", "http://hfd.bvdep.com/ShowNews.asp?", $line);
    PHP Code:
    <html><head><title>Leach Test</title></head>
    <body>
    <B>Financieel dagblad</B><BR>
    <table>
    <?php
    $fileArray 
    file("http://hfd.bvdep.com/Nieuwsdienst.asp");

    if ( ! 
    $fileArray ) {
       echo 
    '<tr><td>The news interface is down for maintenance.</td></tr>',
            
    '</table></body></html>';
       break;
    }   

    $searchStr ='<td class="tekstregulargrey">';
    $i 0;
    foreach(
    $fileArray AS $line) {
       if ( 
    strstr($line$searchStr) ) {
          
    $line str_replace("ShowNews.asp?""http://hfd.bvdep.com/ShowNews.asp?"$line);
          echo 
    $line"\n";
          
    $i++;
       }
       if ( 
    $i == 10 ) {
          break;
       }
    }
    ?>
    </table>
    </body></html>

  7. #7
    SitePoint Enthusiast
    Join Date
    Jun 2001
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    thanks

    Thanks it works. you can see the script working at sander.landzaat.com/dirk/index.php
    The only thing is that the loading time takes so long. Is there any way to make the load goes faster?

    Is it possible that a php script automaticly store the data from other sites to my own file every minute, so my loading time will decrease.
    Last edited by dijksma; Jul 3, 2001 at 06:21.


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
  •