Add additional abbreviations & ensure all have roman numerals
Style fixes
Apply fixes from StyleCI
Parse verse textual representation into book/chapter/verse ranges
Allows you to standardise many different people's bible passage/reference formats and gain programmatic access to them.
A demo of the library's parsing can usually be found at https://bible-verse-parser.techwilk.com/
The code for the demo is in public/
.
Install through composer.
composer require techwilk/bible-verse-parser
Then create a parser
use TechWilk\BibleVerseParser\BiblePassageParser;
$passageParser = new BiblePassageParser();
Just pass in a string, and it will parse into an array of passages. Each range will be a separate object in the array.
Shorthand book abbreviations will be converted into full book names
/** @var BiblePassage[] */
$passages = $passageParser->parse('1 John 5:4-17, 19-21 & Esther 2');
foreach ($passages as $passage) {
echo (string) $passage . PHP_EOL;
}
outputs:
1 John 5:4-17
1 John 5:19-21
Esther 2
Alternatively use the values yourself.
foreach ($passages as $passage) {
echo "From {$passage->from()->book()->name()}";
echo " chapter {$passage->from()->chapter()}";
echo " verse {$passage->from()->verse()}";
echo ", to {$passage->to()->book()->name()}";
echo " chapter {$passage->to()->chapter()}";
echo " verse {$passage->to()->verse()}." . PHP_EOL;
}
outputs:
From 1 John chapter 5 verse 4, to 1 John chapter 5 verse 17.
From 1 John chapter 5 verse 19, to 1 John chapter 5 verse 21.
From Esther chapter 2 verse 1, to Esther chapter 2 verse 23.
Ideal for storing in a database & querying with something like MySQL. The integer notation is the same as several other libraries, with book number in millions, chapter in thousands and verse as ones (1000000 * book) + (1000 * chapter) + verse
.
foreach ($passages as $passage) {
echo $passage->from()->integerNotation();
echo ' (' . (string)$passage->from() . ')' . PHP_EOL;
echo $passage->to()->integerNotation();
echo ' (' . (string)$passage->to() . ')' . PHP_EOL;
echo PHP_EOL;
}
outputs:
62005004 (1 John 5:4)
62005017 (1 John 5:17)
62005019 (1 John 5:19)
62005021 (1 John 5:21)
17002001 (Esther 2:1)
17002023 (Esther 2:23)
We may add additional formats in the future (please open an issue if you use a format which isn't listed.)
John 3:16
John 3v16
John 3vv16
John 3 v16
John 3.16
John 3 16
John c3 v16
John ch3 v16
John chapter 3 verse 16
John 3
John 3, 4
John 3:16-18, 19-22
Gen 1:1; 4:26
John 3:16 & Isiah 22
Is 53: 1-6 & 2 Cor 5: 20-21
Deut 6: 4-9, 16-end & Luke 15: 1-10
1 Peter 2, 5 & Job 34
1 Peter 2:15-16, 18-20
1 John 3:1-4:12