/** * Add the number part of a bible reference (ie, the 3:16 in John 3:16) * * @param BfoxRef $ref * @param integer $book_id * @param string $str */ private static function parse_book_str(BfoxRef &$ref, $book_id, $str) { // Spaces between numbers count as semicolons preg_replace('/(\\d)\\s+(\\d)/', '$1;$2', $str); // Periods between numbers count as colons $str = str_replace('.', ':', $str); $semis = explode(';', $str); foreach ($semis as $semi) { $commas = explode(',', $semi); $verse_chapter = 0; foreach ($commas as $comma) { $dash = explode('-', $comma, 2); $left = explode(':', $dash[0], 2); $ch1 = intval($left[0]); $vs1 = isset($left[1]) ? intval($left[1]) : 0; $ch2 = $vs2 = 0; if (isset($dash[1])) { $right = explode(':', $dash[1], 2); $ch2 = intval($right[0]); $vs2 = isset($right[1]) ? intval($right[1]) : 0; } // We must have a chapter1 if (0 != $ch1) { // If verse0 is not 0, but verse1 is 0, we should use chapter1 as verse1, and chapter1 should be 0 // This fixes the following type of case: 1:2-3 (1:2-3:0 becomes 1:2-0:3) if (0 != $vs1 && 0 == $vs2) { $vs2 = $ch2; $ch2 = 0; } // Whole Chapters (or whole verses) if (0 == $vs1 && 0 == $vs2) { $ref->add_whole($book_id, $ch1, $ch2, $verse_chapter); } elseif (0 == $ch2 || $ch1 == $ch2) { $verse_chapter = $ch1; $ref->add_inner($book_id, $verse_chapter, $vs1, $vs2); } else { $ref->add_mixed($book_id, $ch1, $vs1, $ch2, $vs2, $verse_chapter); $verse_chapter = $ch2; } } } } }