Created
March 30, 2011 14:34
-
-
Save jmather/894506 to your computer and use it in GitHub Desktop.
Convert KJB to array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function processFile($file) | |
{ | |
$file = file_get_contents($file); | |
$book = array(); | |
list($junk, $cont) = explode('<hr>', $file, 2); | |
$cont = trim($cont); | |
preg_match('/<h2>(.*)<\/h2>/U', $cont, $matches); | |
$book['title'] = $matches[1]; | |
$book['chapters'] = array(); | |
preg_match_all('/<h3>(.*)<\/h3>/U', $cont, $matches); | |
foreach($matches[0] as $idx => $chapter_name) | |
{ | |
$chapter = array(); | |
$chapter['name'] = 'Chapter '.($idx + 1); | |
$chapter['verses'] = array(); | |
// get chapter text | |
$begin_pos = strpos($cont, $chapter_name); | |
if (isset($matches[0][($idx + 1)])) | |
{ | |
$end_pos = strpos($cont, $matches[0][($idx + 1)]); | |
$chapter_text = substr($cont, $begin_pos, $end_pos); | |
} else { | |
$end_pos = null; | |
$chapter_text = substr($cont, $begin_pos); | |
} | |
list($text, $junk) = explode('<hr>', $chapter_text); | |
$lines = explode('<br>', $text); | |
foreach($lines as $line) | |
{ | |
$l = trim($line); | |
if (strpos($l, ']') === false) | |
{ | |
continue; | |
} | |
list($junk, $verse) = explode(']', trim($line)); | |
$chapter['verses'][] = $verse; | |
} | |
$book['chapters'][] = $chapter; | |
} | |
return $book; | |
} | |
$info = processFile('text'); | |
print_r($info); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment