Get a table from a website without curl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • boodschap
    New Member
    • Aug 2012
    • 6

    Get a table from a website without curl

    I want to get a specific table from a website and place it on my website. I 'managed' to get the whole site (with fopen and file_get_conten ts). But I need just a table and I don't know where to start :-/
    I want to get the table(s) "agenda" from this website: http://www.keynet.tv/agenda.php?q=us...0381&f=month/2

    or even better: I just need this:

    Please give me something to start coding from...
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Parse the HTML for the table and substring just what you need.

    Comment

    • lyodmichael
      New Member
      • Jul 2012
      • 75

      #3
      hmm, check the source code of the website you want to get :) .

      Comment

      • boodschap
        New Member
        • Aug 2012
        • 6

        #4
        This is a php, might change every now and then. I don't want to put it again every time it's changed. So it should be parsed automatically.. .

        Comment

        • boodschap
          New Member
          • Aug 2012
          • 6

          #5
          I got this, but it doesn't seem to work...
          but you can see what I want to achieve.

          Code:
          $homepage = file_get_contents('http://www.keynet.tv/agenda.php?q=user/show/40381&f=month/1');
          $newstring = substr($homepage, '<h1>Agenda</h1>', strpos($homepage, '<!-- LEGENDE -->'));
          echo($newstring);

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            Your substr syntax is wrong. It takes a string, an integer indicating the position to start, and an optional integer indicating how many characters to return.

            Comment

            • boodschap
              New Member
              • Aug 2012
              • 6

              #7
              solved it with function GetBetween

              Code:
              <?php
              function GetBetween($content,$start,$end){
              	$r = explode($start, $content);
                  if (isset($r[1])){
                      $r = explode($end, $r[1]);
                      return $r[0];
                  }
                  return '';
              }
              ?>
              and that gives:
              Code:
              $homepage = file_get_contents('http://www.keynet.tv/agenda.php?q=user/show/40381&f=month/1');
              $agenda = GetBetween($homepage, '<h1>Agenda</h1>', '<!-- LEGENDE -->');
              echo $agenda;
              did some more coding with GetBetween and str_replace and got what I wanted!

              Comment

              Working...