Skip to content

Instantly share code, notes, and snippets.

@pat-richter
Created May 9, 2017 17:48
Show Gist options
  • Save pat-richter/553770f7dd756f442566435f95ed24ca to your computer and use it in GitHub Desktop.
Save pat-richter/553770f7dd756f442566435f95ed24ca to your computer and use it in GitHub Desktop.
<?php
/**
needs a table with "link" to each chapter
you may get it from sitemap (https://www.bibleserver.com/robots.txt)
**/
error_reporting(E_ALL);
require_once ('sqlwrapper/MysqliDb.php');
require_once ('dom/simple_html_dom.php');
$db = new MysqliDb ('localhost', 'root', 'password', 'leipzig416_test');
$db->where ("text", "");
$chapter = $db->getOne('bible');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $chapter["link"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$html = str_get_html($output);
$links = null;
$aVerses = [];
foreach($html->find('.verse') as $oVerse)
{
$sVerse = $oVerse->plaintext;
$sVerse = preg_replace('/^[\d]+/','', $sVerse);
$sVerse = str_replace('&nbsp;', '', $sVerse);
$sVerse = trim($sVerse);
$aVerses[] = $sVerse;
}
$sVerses = json_encode( $aVerses );
$data = array( 'text' => $sVerses );
try {
$db->where ('id', $chapter['id']);
if ($db->update ('bible', $data)) {
echo $db->count . ' records were updated';
}
else {
echo 'update failed: ' . $db->getLastError();
}
} catch ( Exception $e ) {
echo $e->getMessage();
}
echo '<meta http-equiv="refresh" content="1;url=<?php echo /* self */ ?>" />';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment