Skip to content

ScripturNum ScripturNum

GitHub Actions - update documentation edited this page Nov 22, 2026 · 6 revisions

ScripturNum\ScripturNum

The ScripturNum class, which represents a single continuous passage.

  • Class name: ScripturNum
  • Namespace: \ScripturNum

Constants

BOOK_MASK

const BOOK_MASK = 4278190080

START_MASK

const START_MASK = 16773120

END_MASK

const END_MASK = 4095

BARE_BOOKS_NONE

const BARE_BOOKS_NONE = 'none'

BARE_BOOKS_UNCOMMON

const BARE_BOOKS_UNCOMMON = 'uncommon'

BARE_BOOKS_ALL

const BARE_BOOKS_ALL = 'all'

UNREADABLE_IGNORE

const UNREADABLE_IGNORE = 'ignore'

UNREADABLE_REPORT

const UNREADABLE_REPORT = 'report'

Properties

int

protected mixed int
  • Visibility: protected

book

protected mixed book
  • Visibility: protected

startCh

protected mixed startCh
  • Visibility: protected

startV

protected mixed startV
  • Visibility: protected

endCh

protected mixed endCh
  • Visibility: protected

endV

protected mixed endV
  • Visibility: protected

bibleClass

protected mixed bibleClass = \ScripturNum\Bible::class
  • Visibility: protected

stringSettings

protected mixed stringSettings = ['abbrev' => ['space' => '', 'cvsep' => '.', 'range' => '-', 'names' => 1, 'plurl' => false], 'long' => ['space' => ' ', 'cvsep' => ':', 'range' => '-', 'names' => 0, 'plurl' => true]]
  • Visibility: protected

Methods

__construct

mixed ScripturNum\ScripturNum::__construct(int|string intOrString)

ScripturNum constructor.

  • Visibility: public

Arguments

  • intOrString int|string - ScripturNum int or a human-readable string.

Returns

  • mixed

__get

int ScripturNum\ScripturNum::__get(mixed what)
  • Visibility: public

Arguments

  • what mixed

Returns

  • int -

startInt

mixed ScripturNum\ScripturNum::startInt()
  • Visibility: protected

Returns

  • mixed

endInt

mixed ScripturNum\ScripturNum::endInt()
  • Visibility: protected

Returns

  • mixed

setStringSettings

void ScripturNum\ScripturNum::setStringSettings(mixed key, array settings)

Update string settings.

  • Visibility: public
  • This method is static.

Arguments

  • key mixed* settings array

getInt

int ScripturNum\ScripturNum::getInt()

Get the ScripturNum integer.

  • Visibility: public

Returns

  • int - The ScripturNum integer

__toString

string ScripturNum\ScripturNum::__toString()

Generic toString. Uses the long form.

  • Visibility: public

Returns

  • string -

getAbbrev

string ScripturNum\ScripturNum::getAbbrev()

Get a human-readable abbreviation for the passage. By default, these are meant for usage in short links.

  • Visibility: public

Returns

  • string - An abbreviation

getLongString

string ScripturNum\ScripturNum::getLongString()

Get a human-readable name of the passage. By default, these are meant for humans to read.

  • Visibility: public

Returns

  • string - The name of the passage, as one might pronounce it.

toString

mixed ScripturNum\ScripturNum::toString(mixed options)

Get a string. Publicly-accessible.

  • Visibility: public

Arguments

  • options mixed

Returns

  • mixed

getStringWithSettings

string ScripturNum\ScripturNum::getStringWithSettings(string|array options)

Returns a human-readable string with the settings defined in a given set of settings.

  • Visibility: protected

Arguments

  • options string|array - The setting set to use, or an array of options.

Returns

  • string - The human-intelligible string.

remove

\ScripturNum\ScripturNumArray ScripturNum\ScripturNum::remove(mixed passageToRemove)

Remove a passage from this passage, returning an array of ScripturNum objects that represent the difference.

  • Visibility: public

Arguments

  • passageToRemove mixed

Returns

  • \ScripturNum\ScripturNumArray -

isWholeChapters

bool ScripturNum\ScripturNum::isWholeChapters()

Returns true if the passage is an entire chapter.

  • Visibility: public

Returns

  • bool -

getWholeChapters

static ScripturNum\ScripturNum::getWholeChapters()

Returns a ScripturNum for the current range, expanded to the whole chapter.

  • Visibility: public

Returns

  • static -

getNextChapter

static ScripturNum\ScripturNum::getNextChapter()

Returns a ScripturNum for the chapter after the current highest chapter.

  • Visibility: public

Returns

  • static -

getPrevChapter

static ScripturNum\ScripturNum::getPrevChapter()

Returns a ScripturNum for the chapter prior to the current lowest chapter.

  • Visibility: public

Returns

  • static -

getWholeBook

\ScripturNum\ScripturNum ScripturNum\ScripturNum::getWholeBook()

Get a ScripturNum for the whole book of the Bible that this passage is in, or this one if already a whole book.

  • Visibility: public

Returns

  • \ScripturNum\ScripturNum -

isWholeBook

bool ScripturNum\ScripturNum::isWholeBook()

Returns true if the passage is a whole book.

  • Visibility: public

Returns

  • bool -

isSingleVerse

bool ScripturNum\ScripturNum::isSingleVerse()

Returns true if the passage is just a single verse.

  • Visibility: public

Returns

  • bool -

bookHasSingleChapter

bool ScripturNum\ScripturNum::bookHasSingleChapter()

Returns true if the book only has one chapter (e.g. Jude)

  • Visibility: public

Returns

  • bool -

bookNameToBookNum

int ScripturNum\ScripturNum::bookNameToBookNum(mixed bookName)
  • Visibility: protected
  • This method is static.

Arguments

  • bookName mixed

Returns

  • int -

getBookNames

string[][] ScripturNum\ScripturNum::getBookNames()
  • Visibility: protected
  • This method is static.

Returns

  • string[][] -

getCommonTerms

string[] ScripturNum\ScripturNum::getCommonTerms()
  • Visibility: protected
  • This method is static.

Returns

  • string[] -

getConjunctions

string[] ScripturNum\ScripturNum::getConjunctions()
  • Visibility: protected
  • This method is static.

Returns

  • string[] -

pluralizeBookName

string ScripturNum\ScripturNum::pluralizeBookName(string bookNameSingular)
  • Visibility: protected
  • This method is static.

Arguments

  • bookNameSingular string

Returns

  • string -

newFromParsed

\ScripturNum\ScripturNum ScripturNum\ScripturNum::newFromParsed(string bookStr, ?int startCh, ?int startV, ?int endCh, ?int endV)
  • Visibility: public
  • This method is static.

Arguments

  • bookStr string* startCh ?int* startV ?int* endCh ?int* endV ?int

Returns

  • \ScripturNum\ScripturNum -

newFromInts

\ScripturNum\ScripturNum ScripturNum\ScripturNum::newFromInts(int book, int startCh, int|null startV, int|null endCh, int|null endV)
  • Visibility: public
  • This method is static.

Arguments

  • book int - The book of the Bible the range is within. 1-rel.
  • startCh int - The chapter of the start of the range. 1-rel.
  • startV int|null - The verse of the start of the range. 1-rel. Defaults to 1.
  • endCh int|null - The end chapter of the range. If null or not provided, assumed to be the same as the start chapter.
  • endV int|null - The end verse of the range. If null or not provided, assumed to be the end of the chapter.

Returns

  • \ScripturNum\ScripturNum - The ScripturNum object that represents this range of scripture.

report

void ScripturNum\ScripturNum::report(\ScripturNum\ScripturNumException e, bool|array|null exceptions, string|null input)

Either throws the exception, or--if an array was provided to collect them--adds it to the array. If the exception doesn't already know what text it couldn't read, it is told.

  • Visibility: protected
  • This method is static.

Arguments

  • e ScripturNum\ScripturNumException* exceptions bool|array|null - If an array, the exception is appended to it. Otherwise, it is thrown.
  • input string|null - The text that couldn't be read.

stringToInt

int ScripturNum\ScripturNum::stringToInt(string string)

Takes a string that represents a single passage and returns it as an int.

  • Visibility: public
  • This method is static.

Arguments

  • string string - A human-readable scripture reference that should be converted to an int.

Returns

  • int - The int.

stringToInts

int[] ScripturNum\ScripturNum::stringToInts(string string, bool|array exceptions)

Takes a reference string for a single book and returns a plurality of ints for corresponding passages. This should only be passed values that are known to be references, not just any text.

Replacement: use parseString() with every book name allowed and unreadable text reported:

$passages = ScripturNum::parseString($string, ScripturNum::BARE_BOOKS_ALL, ScripturNum::UNREADABLE_REPORT, $exceptions);

The differences are that the replacement:

  • Returns a ScripturNumArray, not an array of ints. Call getInt() on each passage to get the ints.
  • Puts the passages in the order of the Bible, and combines any that overlap or are adjacent (so "John 3:16, 17" is one passage, not two), whereas this method keeps the passages in the order written.
  • Reads references to more than one book (e.g. "John 3:16; Romans 8"), which this method does not.

Passing an array for $exceptions has the same effect in both. Without one, the first exception is thrown.

  • Visibility: public
  • This method is static.

Arguments

  • string string - A human-readable scripture reference that should be converted to one or more ints. Allows for commas and semicolons.
  • exceptions bool|array - Pass an array to this parameter, and it will be populated with any exceptions that occur. By passing an array, this will not throw the exception, and by not throwing the exception, execution continues and you may be apprised of multiple errors that may exist.

Returns

  • int[] - The ints.

normalize

string ScripturNum\ScripturNum::normalize(string string)

Standardizes the punctuation and whitespace of reference text, so that conjunctions, "through", and the like are expressed as the separators that the parser understands.

  • Visibility: protected
  • This method is static.

Arguments

  • string string

Returns

  • string -

punctuationPatterns

string[][] ScripturNum\ScripturNum::punctuationPatterns()

The words and symbols (the language's conjunctions, and the various dashes) that stand for separators, as regular expressions, and the kinds of space. Words must stand alone, so "and" within "Sandy" is not a conjunction, and neither is "y" within the Spanish "Reyes", or next to a digit. Anything that isn't a letter or digit is a break. Case doesn't matter.

  • Visibility: protected
  • This method is static.

Returns

  • string[][] - Each is [the regular expression, what it is replaced with by normalize(), what it is replaced with (before being padded to its original length) by maskPunctuation()].

parseSpan

int[] ScripturNum\ScripturNum::parseSpan(string string, bool|array exceptions)

Parses a single span: one book's name, followed by any number of references within that book.

  • Visibility: protected
  • This method is static.

Arguments

  • string string - The span, e.g. "John 3:16, 18; 4:2"
  • exceptions bool|array - Pass an array to have exceptions collected, rather than thrown.

Returns

  • int[] -

singleChapterBookNumbersAreVerses

void ScripturNum\ScripturNum::singleChapterBookNumbersAreVerses(int book, ?int startCh, ?int startV, ?int endCh, ?int endV)

In a book of only one chapter (Obadiah, Philemon, 2 John, 3 John, and Jude), a number that is written alone is a verse, and not the chapter. So "Jude 1" is verse 1, as "Jude 5" is verse 5, and as "Jude 1:1" is. This makes what getAbbrev() writes for the first verse (such as "Ob1") readable. A book's whole is written as its name.

This is for numbers that were read from a string. (Numbers larger than 1 are made into verses by validateRefNums(), which is also used for numbers that weren't.)

  • Visibility: protected
  • This method is static.

Arguments

  • book int - The book number, starting from 1.
  • startCh ?int* startV ?int* endCh ?int* endV ?int

validateRefNums

void ScripturNum\ScripturNum::validateRefNums(int book, ?int startCh, ?int startV, ?int endCh, ?int endV)

Validate that reference numbers can be matched to verses that exist.

  • Visibility: protected
  • This method is static.

Arguments

  • book int* startCh ?int* startV ?int* endCh ?int* endV ?int

refNumsToInt

int ScripturNum\ScripturNum::refNumsToInt(int book, ?int startCh, ?int startV, ?int endCh, ?int endV)

Take reference indexes and convert them to the ScripturNum int. Assumes numbers are already validated by either safely existing or being validated against self::validateRefNums()

  • Visibility: protected
  • This method is static.

Arguments

  • book int* startCh ?int* startV ?int* endCh ?int* endV ?int

Returns

  • int -

refNumStringToRefNums

mixed ScripturNum\ScripturNum::refNumStringToRefNums(string string, mixed chapterStart, mixed verseStart, mixed chapterEnd, mixed verseEnd, bool useHints)

This function reads through a single ref string (e.g. 3:5-6:9) one character at a time to parse it into a known reference.

  • Visibility: protected
  • This method is static.

Arguments

  • string string - The string to parse.
  • chapterStart mixed* verseStart mixed* chapterEnd mixed* verseEnd mixed* useHints bool - If true, will consider the values provided to the chapter and verse parameters in parsing the string. Default false.

Returns

  • mixed

intToRefNums

mixed ScripturNum\ScripturNum::intToRefNums(int int, int book, int chapterStart, int verseStart, int chapterEnd, int verseEnd)

Converts a ScripturNum int into reference numbers.

  • Visibility: protected
  • This method is static.

Arguments

  • int int - The ScripturNum integer
  • book int - The book number
  • chapterStart int - The first Chapter
  • verseStart int - The first Verse
  • chapterEnd int - The last Chapter
  • verseEnd int - The last Verse

Returns

  • mixed

intToConcats

mixed ScripturNum\ScripturNum::intToConcats(int int, string|int concatStart, string|int concatEnd)

Convert a ScrupturNum int into a concatenated number. (Concatenated numbers are often used for text libraries.)

  • Visibility: public
  • This method is static.

Arguments

  • int int - The int representing the full passage
  • concatStart string|int - The concatenated "number" possibly larger than an int representing the start of the passage.
  • concatEnd string|int - The concatenated "number" possibly larger than an int representing the end of the passage.

Returns

  • mixed

bkIndexToSingleRef

mixed ScripturNum\ScripturNum::bkIndexToSingleRef(int book, int index, int chapter, int verse)

Parse a book index number into a chapter and verse.

  • Visibility: protected
  • This method is static.

Arguments

  • book int - Book number
  • index int - Verse Index Number
  • chapter int - Chapter
  • verse int - Verse

Returns

  • mixed

extractFromString

\ScripturNum\ScripturNumArray ScripturNum\ScripturNum::extractFromString(string string, bool excludeAllBookOnlyRefs, null exceptions)

Given a string with any kind of text content, this method will search for any human-readable scripture references and try to parse them into discrete passages. Returns a ScripturNumArray.

Replacement: use parseString(), which returns the same thing and takes the same $exceptions. The $excludeAllBookOnlyRefs flag becomes the $bareBookNames option:

// extractFromString($string, false, $exceptions) is the same as:
ScripturNum::parseString($string, ScripturNum::BARE_BOOKS_UNCOMMON, ScripturNum::UNREADABLE_IGNORE, $exceptions);

// extractFromString($string, true, $exceptions) is the same as:
ScripturNum::parseString($string, ScripturNum::BARE_BOOKS_NONE, ScripturNum::UNREADABLE_IGNORE, $exceptions);

The options in the first example are the defaults, so if $exceptions isn't needed, it is simply parseString($string).

  • Visibility: public
  • This method is static.

Arguments

  • string string* excludeAllBookOnlyRefs bool* exceptions null - To have exceptions collected rather than thrown, pass an array to this parameter.

Returns

  • \ScripturNum\ScripturNumArray -

parseString

\ScripturNum\ScripturNumArray ScripturNum\ScripturNum::parseString(string string, string bareBookNames, string unreadableText, bool|array exceptions)

Finds and parses the scripture references in a string. The string may be prose with references in it, or text that is known to be a list of references, such as what a person types into a "scripture" field. The options say which of these to expect.

Prose (the defaults): references are found wherever they appear, and everything else is skipped.

ScripturNum::parseString('Read John 3:16 and Romans 8 today.');   // John 3:16, Romans 8

A list of references: every reference that can be read is returned, and every item that can't is reported with its text, so that a person can be told what wasn't understood. Book names are always allowed on their own, since there's no prose to protect. Each item that can't be read is reported separately.

$exceptions = [];
$passages = ScripturNum::parseString('Romans 8; Hezekiah 1; Acts 2:38',
                                     ScripturNum::BARE_BOOKS_ALL,
                                     ScripturNum::UNREADABLE_REPORT,
                                     $exceptions);
// $passages has Acts 2:38 and Romans 8.  $exceptions has one exception, and $exceptions[0]->getInput() is
// "Hezekiah 1".

Items can be separated by semicolons, commas, line breaks, and the language's conjunction for "and". A separator followed by chapters or verses continues the same book ("John 3:16; 4:2" is John 3:16 and John 4:2), and one followed by a book name starts a new passage. Empty items are ignored.

A chapter and a verse can be separated by either ":" or "." ("John 3:16" and "John 3.16" are the same), so that the short form that getAbbrev() writes ("Jn3.16") can be read. In a book of one chapter, a number that is alone is a verse ("Jude 5", and "Ob1" for Obadiah 1:1).

Book names, common terms and conjunctions are those of the class that this is called on, so a class with another language's Bible reads that language.

The passages are returned in a ScripturNumArray, which puts them in the order of the Bible and combines any that overlap or are adjacent. Each is an instance of the class this was called on.

References that are found but are not valid (e.g. John 3:99) are always reported, whatever $unreadableText is.

  • Visibility: public
  • This method is static.

Arguments

  • string string - The text to read.
  • bareBookNames string - Whether a book name with nothing after it counts as a reference to the whole book. One of:
  • BARE_BOOKS_NONE: never. "John 3" is found, but "John" is not.
  • BARE_BOOKS_UNCOMMON: only if the name isn't a common word, as listed by Bible::getCommonTerms(). "Genesis" is found, but "Mark" and "Job" are not, which keeps "mark my words" from being read as the book of Mark. This is the default.
  • BARE_BOOKS_ALL: always, even for common words. A name that is part of a longer reference ("John 3:16") is not also returned as the whole book.
  • unreadableText string - What to do with text that isn't a reference. One of:
  • UNREADABLE_IGNORE: skip it. This is the default.
  • UNREADABLE_REPORT: report it as an exception, with the text available from the exception's getInput(). Each item (text between semicolons, commas, ampersands, line breaks and conjunctions) is reported separately. Separators and conjunctions don't count as text.
  • exceptions bool|array - To have exceptions collected rather than thrown, pass an array. Otherwise, the first exception is thrown.

Returns

  • \ScripturNum\ScripturNumArray -

maskPunctuation

string ScripturNum\ScripturNum::maskPunctuation(string string)

Replaces conjunctions, dashes, and the like with the separator they stand for, so that they can be recognized when scanning. The length in bytes is preserved, so that offsets in the result are also offsets in the original.

  • Visibility: protected
  • This method is static.

Arguments

  • string string

Returns

  • string -

scan

array[] ScripturNum\ScripturNum::scan(string masked, string bareBookNames)

Finds the spans of a string that look like references. Either a ":" or a "." can be between a chapter and a verse, so that what getAbbrev() writes ("Jn3.16") is found. (A "." counts only if a digit follows it right away, so that the period that ends a sentence about "Psalm 23." is not a separator.)

  • Visibility: protected
  • This method is static.

Arguments

  • masked string - The string, as processed by maskPunctuation().
  • bareBookNames string - One of the BARE_BOOKS_* constants.

Returns

  • array[] - Each is [the matched text, its offset], in the order found. Matches that overlap an earlier one are left out.

unreadableItems

string[] ScripturNum\ScripturNum::unreadableItems(string original, string masked, int from, int to)

Gets the items in part of the original string that are neither references nor mere separators. Items are separated by semicolons, commas, ampersands, line breaks, and conjunctions.

  • Visibility: protected
  • This method is static.

Arguments

  • original string* masked string - The string, as processed by maskPunctuation().
  • from int - Offset of the start of the part to check.
  • to int - Offset of the end of the part to check.

Returns

  • string[] - The original text of each item, without surrounding separators. Empty if there is nothing but separators.

isWithinInt

bool ScripturNum\ScripturNum::isWithinInt(int largerPassage)

Test whether a given passage is within a given larger passage. Will also return true if they are the same.

  • Visibility: public

Arguments

  • largerPassage int

Returns

  • bool -

isWithin

bool ScripturNum\ScripturNum::isWithin(\ScripturNum\ScripturNum largerPassage)

Test whether a given passage is within a given larger passage. Will also return true if they are the same.

  • Visibility: public

Arguments

Returns

  • bool -

overlapsWithInt

bool ScripturNum\ScripturNum::overlapsWithInt(int otherPassage)

Test whether a given passage has any commonality with another passage.

  • Visibility: public

Arguments

  • otherPassage int

Returns

  • bool -

overlapsWith

bool ScripturNum\ScripturNum::overlapsWith(\ScripturNum\ScripturNum otherPassage)

Test whether a given passage has any commonality with another passage.

  • Visibility: public

Arguments

Returns

  • bool -

overlapsOrAdjacentInt

bool ScripturNum\ScripturNum::overlapsOrAdjacentInt(int otherPassage)

Test whether a given passage has any commonality with another passage, or is adjacent to it.

  • Visibility: public

Arguments

  • otherPassage int

Returns

  • bool -

overlapsOrAdjacent

bool ScripturNum\ScripturNum::overlapsOrAdjacent(\ScripturNum\ScripturNum otherPassage)

Test whether a given passage has any commonality with another passage, or is adjacent to it.

  • Visibility: public

Arguments

Returns

  • bool -

combineWithInt

int ScripturNum\ScripturNum::combineWithInt(int otherPassage)

Combines two adjacent or overlapping passages into one int.

  • Visibility: public

Arguments

  • otherPassage int

Returns

  • int -

combineWith

\ScripturNum\ScripturNum ScripturNum\ScripturNum::combineWith(\ScripturNum\ScripturNum otherPassage)

Combines two adjacent or overlapping passages into one ScripturNum.

  • Visibility: public

Arguments

Returns

  • \ScripturNum\ScripturNum -

containsInt

bool ScripturNum\ScripturNum::containsInt(int smallerPassage)

Test whether a given passage contains a given smaller passage. Will also return true if they are the same.

  • Visibility: public

Arguments

  • smallerPassage int

Returns

  • bool -

contains

bool ScripturNum\ScripturNum::contains(\ScripturNum\ScripturNum smallerPassage)

Test whether a given passage contains a given smaller passage. Will also return true if they are the same.

  • Visibility: public

Arguments

Returns

  • bool -

toSqlExclusive

string ScripturNum\ScripturNum::toSqlExclusive(string columnRef)

Generate a query statement that can be used to search an int column in generic SQL for a passage that is entirely contained within the given ScripturNum.

  • Visibility: public

Arguments

  • columnRef string - The name of the column or value to use in the query.

Returns

  • string -

toSqlExclusive3

string ScripturNum\ScripturNum::toSqlExclusive3(string bookColumnRef, string startColumnRef, string endColumnRef)

Generate a query statement that can be used to search three numeric columns in generic SQL for a passage that is entirely contained within the given ScripturNum. The three columns should represent book, start index, and end index respectively.

  • Visibility: public

Arguments

  • bookColumnRef string - The name of the column or value to use for the book index.
  • startColumnRef string - The name of the column or value to use for the start index.
  • endColumnRef string - The name of the column or value to use for the end index.

Returns

  • string -

toSqlInclusive

string ScripturNum\ScripturNum::toSqlInclusive(string columnRef)

Generate a query statement that can be used to search an int column in generic SQL for a passage that overlaps with the given ScripturNum.

  • Visibility: public

Arguments

  • columnRef string - The name of the column or value to use in the query.

Returns

  • string -

toSqlInclusive3

string ScripturNum\ScripturNum::toSqlInclusive3(string bookColumnRef, string startColumnRef, string endColumnRef)

Generate a query statement that can be used to search three numeric columns in generic SQL for a passage that overlaps with the given ScripturNum. The three columns should represent book, start index, and end index respectively.

  • Visibility: public

Arguments

  • bookColumnRef string - The name of the column or value to use for the book index.
  • startColumnRef string - The name of the column or value to use for the start index.
  • endColumnRef string - The name of the column or value to use for the end index.

Returns

  • string -

getWholeBible

\ScripturNum\ScripturNumArray ScripturNum\ScripturNum::getWholeBible()

Get a ScripturNumArray representing the whole Bible.

  • Visibility: public
  • This method is static.

Returns

  • \ScripturNum\ScripturNumArray -

Clone this wiki locally