Get a table from a website without curl – PHP

  php

Q(Question):

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_contents). 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…

A(Answer):

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

A(Answer):

hmm, check the source code of the website you want to get 🙂 .

A(Answer):

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…

A(Answer):

I got this, but it doesn’t seem to work…
but you can see what I want to achieve.

$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);

A(Answer):

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.

A(Answer):

solved it with function GetBetween

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

$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!

LEAVE A COMMENT