Die $html-class van simplhtmldom is echt de bom. Dat werkt als een trein.
Werkt je class-aanroep wel? Dus alles juist geïncluded en aangeroepen?
Het kan ook ongeveer zo: (dit haalt een stuk tekst weg uit een lap html):
<?php
// TAAK 1: verkrijg meditatie
// TAAK 1: verkrijg meditatie
$tekst = file_get_contents('http://hghg.nl/index.php?view=article&catid=16%3Akerkbode&id=522%3Akerkbode-68-18&tmpl=component&print=1&layout=default&page=&option=com_content&Itemid=24');
//$tekst = htmlentities($tekst);
$tekst = tussen($tekst, '<strong>', '<p align="center">');
$tekst = strip_tags($tekst, "<em></em>");
$tekst = str_replace(array(" ", "\t", '‘', '’', '“', '”'), '', $tekst);
$regels = explode(PHP_EOL, $tekst);
$regels = array_filter($regels, create_function('$a', 'return trim($a)!="";'));
$regels = array_values($regels);
// verkrijg delen
$titel = trim($regels[0]);
list($vers, $locatie) = explode("</em>", $regels[1]);
$vers = '<i>' . str_replace("<em>", '', $vers) . '</i>';
$locatie = '<u>' . trim(str_replace(array("(", ")"), '', $locatie)) . '</u>';
$schrijver = end($regels);
$tekst = array_slice($regels, 2, (count($regels) - 3));
$tekst = '<p>' . implode("</p>\n</p>", $tekst) . '</p>';
echo '<h1>' . $titel . '</h1>' . $vers . $locatie . '<br><br><br>' . $tekst . '<br><br><br>' . $schrijver;
?>
En iets moeilijker, met inloggen etc.
Dit haalt alle uitzendingen van kerkdienstgemist.nl:
[code]<?php
// TAAK 3: preken downloaden van kerkuitzendinggemist.nl
$pagina = 'http://kerkdienstgemist.nl/playlists/legacy.html?id=369';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $pagina);
// set url to post to
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 600000);
// times out after Ns
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
// times out after Ns
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_POST, 0);
// set POST method
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$res = curl_exec($ch);
$res = tussen($res, "<table border='0' cellpadding='0' cellspacing='0' class='center'>", '</table>');
//$res = strip_tags($res, "<a></a><img>");
$res = explode("</tr>", $res);
$res = array_slice($res, 0, 3);
foreach($res as $res2)
{
$url = tussen($res2, "</td>" . PHP_EOL . "<td class='buttons'>", '" title="Downloaden');
$url = str_replace('<a href="', 'http://kerkdienstgemist.nl', $url);
$url = trim($url);
$echo[] = 'cURL() haalt '.$url.' op.';
// stap 3b
$pagina = $url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $pagina);
// set url to post to
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 600000);
// times out after Ns
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
// times out after Ns
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_POST, 0);
// set POST method
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$res = curl_exec($ch);
// <html><body>You are being <a
// href="http://media.kerkdienstgemist.nl:80/11304060/2012-06-10-1800.mp3?Signature=13U0StxNq7K%2BUn%2BmmTJ3cb8q6d8%3D&Expires=1339865566&AWSAccessKeyId=1VYKRTJ5FFKT5B6F4NR2">redirected</a>.</body></html>
$res = str_replace('<html><body>You are being <a href="', '', $res);
$res = str_replace('">redirected</a>.</body></html>', '', $res);
//$echo[] = 'cURL() heeft het echte pad verkregen: '.$res;
// stap 3c, bestand downloaden en opslaan
// bewerk en verkrijg gegevens voor opslag
$naam = $url = $res;
// naam krijgen
$naam = str_replace("http://media.kerkdienstgemist.nl:80/", "", $naam);
list($nummer, $datum_en_meer) = explode("/", $naam);
list($datum, $opties) = explode("?", $datum_en_meer);
$naam = $datum;
// datum krijgen
$datum = str_replace(".mp3", "", $naam);
$datum = $datum;
list($jaar, $maand, $dag, $tijd) = explode("-", $datum);
$tijd = substr($tijd, 0, 2) . ":" . substr($tijd, 2, 2) . ':00';
$datum = $jaar . '-' . $maand . '-' . $dag . ' ' . $tijd;
?>
Uiteraard sla ik het ook nog een keer op ;).