public static function interpretPassage($currentPassage, $rawPassage) { $rawPassage = Filter_Books::cleanPassage($rawPassage); // Create an array with the bits of the raw input. $input = explode(" ", $rawPassage); // Go through the array from verse to chapter to book. // Check how many numerals it has after the book part. $numerals = array(); $book = ""; $invertedInput = array_reverse($input); foreach ($invertedInput as $bit) { if (Filter_Numeric::integer_in_string($bit) != "") { $numerals[] = $bit; array_pop($input); } else { $book = implode(" ", $input); break; } } // Deal with: Only book given, e.g. "Genesis". if ($book != "" && count($numerals) == 0) { return Filter_Books::explodePassage("{$book} 1 1"); } else { if ($book == "" && count($numerals) == 1) { $book = $currentPassage[0]; $chapter = $currentPassage[1]; $verse = $numerals[0]; $passage = Filter_Books::explodePassage("Unknown {$chapter} {$verse}"); $passage[0] = $book; return $passage; } else { if ($book == "" && count($numerals) == 2) { $book = $currentPassage[0]; $chapter = $numerals[1]; $verse = $numerals[0]; $passage = Filter_Books::explodePassage("Unknown {$chapter} {$verse}"); $passage[0] = $book; return $passage; } else { if ($book != "" && count($numerals) == 1) { $chapter = $numerals[0]; return Filter_Books::explodePassage("{$book} {$chapter} 1"); } else { if ($book != "" && count($numerals) == 2) { return Filter_Books::explodePassage($rawPassage); } } } } } // Give up. return $currentPassage; }