I’m in the process of creating a WordPress plugin that automatically links bible references. I’ve largely mashed together two existing plugins for this and have been making other adjustments from there and they used two different ways of storing all of the book titles/abbreviations. What I would like to do is make it stored only in one place and then have it implode to use in the other. I believe that the implode function should work to do this, but I seem to not quite get it right.
I have a variable $bookHash which uses numbers for the book along with an array of strings that match it:
[php]function add_book_to_hash($number, $names)
{
global $bookHash;
foreach ($names as &$name)
{
$bookHash[$name] = $number;
}
}
function populate_book_hash()
{
global $bookHash;
if (count($bookHash)>0) return;
init_vl_sites();
add_book_to_hash(1, array(“genesis”,“gen”,“ge”,“gn”));
add_book_to_hash(2, array(“exodus”,“exo”,“ex”,“exod”));
add_book_to_hash(3, array(“leviticus”,“lev”,“le”,“lv”));
add_book_to_hash(4, array(“numbers”,“num”,“nu”));
add_book_to_hash(5, array(“deuteronomy”,“deut”,“dt”,“de”,“deu”));
add_book_to_hash(6, array(“joshua”,“josh”,“jos”,“jsh”));
add_book_to_hash(7, array(“judges”,“judg”,“jdg”,“jg”,“jdgs”,“jug”));
add_book_to_hash(8, array(“ruth”,“rth”,“ru”,“rut”));
add_book_to_hash(9, array(“1 samuel”,“1 sam”,“1 sa”,“1samuel”,“1s”,“i sa”,“1 sm”,“1sa”,“i sam”,“1sam”,“i samuel”,“1st samuel”,“first samuel”));
add_book_to_hash(10, array(“2 samuel”,“2 sam”,“2 sa”,“2s”,“ii sa”,“2 sm”,“2sa”,“ii sam”,“2sam”,“ii samuel”,“2samuel”,“2nd samuel”,“second samuel”));
add_book_to_hash(11, array(“1 kings”,“1 kgs”,“1 ki”,“1k”,“i kgs”,“1kgs”,“i ki”,“1ki”,“i kings”,“1kings”,“1st kgs”,“1st kings”,“first kings”,“first kgs”,“1kin”));
add_book_to_hash(12, array(“2 kings”,“2 kgs”,“2 ki”,“2k”,“ii kgs”,“2kgs”,“ii ki”,“2ki”,“ii kings”,“2kings”,“2nd kgs”,“2nd kings”,“second kings”,“second kgs”,“2kin”));
add_book_to_hash(13, array(“1 chronicles”,“1 chron”,“1 ch”,“i ch”,“1ch”,“1 chr”,“i chr”,“1chr”,“i chron”,“1chron”,“i chronicles”,“1chronicles”,“1st chronicles”,“first chronicles”));
add_book_to_hash(14, array(“2 chronicles”,“2 chron”,“2 ch”,“ii ch”,“2ch”,“ii chr”,“2chr”,“ii chron”,“2chron”,“ii chronicles”,“2chronicles”,“2nd chronicles”,“second chronicles”));
add_book_to_hash(15, array(“ezra”,“ezr”));
add_book_to_hash(16, array(“nehemiah”, “neh”, “ne”));
add_book_to_hash(17, array(“esther”,“esth”,“es”,“est”));
add_book_to_hash(18, array(“job”,“jb”));
add_book_to_hash(19, array(“psalms”,“pslm”,“ps”,“psalm”,“psa”,“psm”,“pss”));
add_book_to_hash(20, array(“proverbs”,“prov”,“pr”,“prv”,“pro”));
add_book_to_hash(21, array(“ecclesiastes”,“eccles”,“ec”,“ecc”));
add_book_to_hash(22, array(“song of solomon”,“song”,“so”,“song of songs”,“sos”,“son”));
add_book_to_hash(23, array(“isaiah”,“isa”,“is”));
add_book_to_hash(24, array(“jeremiah”,“jer”,“je”,“jr”));
add_book_to_hash(25, array(“lamentations”,“lam”,“la”));
add_book_to_hash(26, array(“ezekiel”,“ezek”,“eze”,“ezk”));
add_book_to_hash(27, array(“daniel”,“dan”,“da”,“dn”));
add_book_to_hash(28, array(“hosea”,“hos”,“ho”));
add_book_to_hash(29, array(“joel”,“joe”,“jl”));
add_book_to_hash(30, array(“amos”,“am”,“amo”));
add_book_to_hash(31, array(“obadiah”,“obad”,“ob”,“oba”));
add_book_to_hash(32, array(“jonah”,“jnh”,“jon”));
add_book_to_hash(33, array(“micah”,“mic”));
add_book_to_hash(34, array(“nahum”, “nah”, “na”));
add_book_to_hash(35, array(“habakkuk”,“hab”,“ha”));
add_book_to_hash(36, array(“zephaniah”,“zeph”,“zep”,“zp”));
add_book_to_hash(37, array(“haggai”,“hag”,“hg”));
add_book_to_hash(38, array(“zechariah”,“zech”,“zec”,“zc”));
add_book_to_hash(39, array(“malachi”,“mal”,“ml”));
add_book_to_hash(40, array(“matthew”,“matt”,“mt”,“mat”));
add_book_to_hash(41, array(“mark”,“mrk”,“mk”,“mr”,“mak”));
add_book_to_hash(42, array(“luke”,“luk”,“lk”,“lu”));
add_book_to_hash(43, array(“john”,“jn”,“jhn”,“joh”));
add_book_to_hash(44, array(“acts”,“ac”,“act”));
add_book_to_hash(45, array(“romans”,“rom”,“ro”,“rm”));
add_book_to_hash(46, array(“1 corinthians”,“1 cor”,“1 co”,“i co”,“1co”,“i cor”,“1cor”,“i corinthians”,“1corinthians”,“1st corinthians”,“first corinthians”,“1 corin”));
add_book_to_hash(47, array(“2 corinthians”,“2 cor”,“2 co”,“ii co”,“2co”,“ii cor”,“2cor”,“ii corinthians”,“2corinthians”,“2nd corinthians”,“second corinthians”,“2 corin”));
add_book_to_hash(48, array(“galatians”,“gal”,“ga”));
add_book_to_hash(49, array(“ephesians”,“ephes”,“eph”));
add_book_to_hash(50, array(“philippians”,“phil”,“php”,“phl”));
add_book_to_hash(51, array(“colossians”,“col”));
add_book_to_hash(52, array(“1 thessalonians”,“1 thess”,“1 th”,“i th”,“1th”,“i thes”,“1thes”,“i thess”,“1thess”,“i thessalonians”,“1thessalonians”,“1st thessalonians”,“first thessalonians”,“1ts”));
add_book_to_hash(53, array(“2 thessalonians”,“2 thess”,“2 th”,“ii th”,“2th”,“ii thes”,“2thes”,“ii thess”,“2thess”,“ii thessalonians”,“2thessalonians”,“2nd thessalonians”,“second thessalonians”,“2ts”));
add_book_to_hash(54, array(“1 timothy”,“1 tim”,“1 ti”,“i ti”,“1ti”,“i tim”,“1tim”,“i timothy”,“1timothy”,“1st timothy”,“first timothy”));
add_book_to_hash(55, array(“2 timothy”,“2 tim”,“2 ti”,“ii ti”,“2ti”,“ii tim”,“2tim”,“ii timothy”,“2timothy”,“2nd timothy”,“second timothy”));
add_book_to_hash(56, array(“titus”,“tit”,“ti”));
add_book_to_hash(57, array(“philemon”,“philem”,“phm”,“phlm”));
add_book_to_hash(58, array(“hebrews”,“heb”));
add_book_to_hash(59, array(“james”,“jas”,“jm”));
add_book_to_hash(60, array(“1 peter”,“1 pet”,“1 pe”,“i pe”,“1pe”,“i pet”,“1pet”,“i pt”,“1 pt”,“1pt”,“i peter”,“1peter”,“1st peter”,“first peter”));
add_book_to_hash(61, array(“2 peter”,“2 pet”,“2 pe”,“ii pe”,“2pe”,“ii pet”,“2pet”,“ii pt”,“2 pt”,“2pt”,“ii peter”,“2peter”,“2nd peter”,“second peter”));
add_book_to_hash(62, array(“1 john”,“1 jn”,“i jn”,“1jn”,“i jo”,“1jo”,“i joh”,“1joh”,“i jhn”,“1 jhn”,“1jhn”,“i john”,“1john”,“1st john”,“first john”));
add_book_to_hash(63, array(“2 john”,“2 jn”,“ii jn”,“2jn”,“ii jo”,“2jo”,“ii joh”,“2joh”,“ii jhn”,“2 jhn”,“2jhn”,“ii john”,“2john”,“2nd john”,“second john”));
add_book_to_hash(64, array(“3 john”,“3 jn”,“iii jn”,“3jn”,“iii jo”,“3jo”,“iii joh”,“3joh”,“iii jhn”,“3 jhn”,“3jhn”,“iii john”,“3john”,“3rd john”,“third john”));
add_book_to_hash(65, array(“jude”,“jud”));
add_book_to_hash(66, array(“revelation”,“rev”,“re”));
add_book_to_hash(67, array(“tobit”, “tob”));
add_book_to_hash(68, array(“judith”, “judth”, “jdt”));
add_book_to_hash(69, array(“additions to esther”, “additions to ester”, “greek esther”, “greek ester”));
add_book_to_hash(70, array(“wisdom”, “wis”));
add_book_to_hash(71, array(“sirach”, “sir”, “si”));
add_book_to_hash(72, array(“baruch”, “bar”, “ba”));
add_book_to_hash(73, array(“letter of jeremiah”, “letter of jer”));
add_book_to_hash(74, array(“prayer of azariah”));
add_book_to_hash(75, array(“susanna”, “sus”, “su”));
add_book_to_hash(76, array(“bel and the dragon”, “bel”));
add_book_to_hash(77, array(“1 maccabees”, “1 macc”, “1 mac”, “1maccabees”, “1macc”, “1mac”, “i maccabees”, “i macc”, “i mac”));
add_book_to_hash(78, array(“2 maccabees”, “2 macc”, “2 mac”, “2maccabees”, “2macc”, “2mac”, “ii maccabees”, “ii macc”, “ii mac”));
add_book_to_hash(79, array(“1 esdras”, “1 esd”, “1 es”, “i esdras”, “i esd”, “i es”, “1esdras”, “1esd”, “1es”));
add_book_to_hash(80, array(“2 esdras”, “2 esd”, “2 es”, “ii esdras”, “ii esd”, “ii es”, “2esdras”, “2esd”, “2es”));
add_book_to_hash(81, array(“prayer of manasseh”, “manasseh”, “man”));
}[/php]
Then I want it to essentially generate this, either divided as it is now or all into one big $book_regex:
[php] $volume_regex = ‘1|2|3|I|II|III|1st|2nd|3rd|First|Second|Third’;
// Regular Expression for OT Book full name strings
$book_ot_regex = ‘Genesis|Exodus|Leviticus|Numbers|Deuteronomy|Joshua|Judges|Ruth|Samuel|Kings|Chronicles|Ezra|Nehemiah|Esther’;
$book_ot_regex .= ‘|Job|Psalms?|Proverbs?|Ecclesiastes|Songs? of Solomon|Song of Songs|Isaiah|Jeremiah|Lamentations|Ezekiel|Daniel|Hosea|Joel|Amos|Obadiah|Jonah|Micah|Nahum|Habakkuk|Zephaniah|Haggai|Zechariah|Malachi’;
$book_dc_regex = ‘|Tobit|Judith|Greek Esther|Wisdom|Sirach|Ecclesiasticus|Sirach (Ecclesiasticus)|Baruch|Letter of Jeremiah|(Prayer of )?Azariah( and the Song of the Three Young Men)?|Susanna|Bel( and the Dragon)?|1 Maccabees|2 Maccabees|1 Esdras|2 Esdras|Prayer of Manasseh’;
// Regular Expression for NT Book full name strings
$book_nt_regex = ‘|Mat+hew|Mark|Luke|John|Acts?|Acts of the Apostles|Romans|Corinthians|Galatians|Ephesians|Phil+ippians|Colossians|Thessalonians|Timothy|Titus|Philemon|Hebrews|James|Peter|Jude|Revelations?’;
// Separate abbreviations from full names in order to find abbreviated book names followed by a period
// Regular Expression for OT Book abbreviation strings
$abbrev_ot_regex = ‘Gen|Ex|Exo|Lev|Num|Nmb|Deut?|Josh?|Judg?|Jdg|Rut|Sam|Ki?n|Chr(?:on?)?|Ezr|Neh|Est’;
$abbrev_ot_regex .= ‘|Jb|Psa?|Pr(?:ov?)?|Eccl?|Song?|Isa|Jer|Lam|Eze|Dan|Hos|Joe|Amo|Oba|Jon|Mic|Nah|Hab|Zeph?|Hag|Zech?|Mal’;
$abbrev_dc_regex = ‘|Tob|Jd?th|Gr(eek)? Est?|Wisd?|Sir?|Ba|Let(ter)? of Jer|Prayer of Az|Az|Sus|Macc?|Esd?|Pray(er)? of Man’;
// Regular Expression for NT Book abbreviation strings
$abbrev_nt_regex = ‘|Mat+|Mr?k|Lu?k|Jh?n|Jo|Act|Rom|Cor|Gal|Eph|Col|Phil?|The?|Thess?|Tim|Tit|Phile|Heb|Ja?m|Pe?t|Ju?d|Rev’;[/php]
It wasn’t a big deal for me to do it manually once, since I copied from the other plugins, but I now need to expand it to French and am realizing how unnecessary it is to copy it all out repeatedly.