Bible Class

The Bible class provides a simple way of loading and printing Bible verses. Here is some code that demonstrates how to use the object:



<?php
// This loads the Bible.php and makes it available
require_once('Bible.php');

// This creates a bible object with the King James Version loaded
$bible = new Bible('kjv');

// This returns the selected verses in a blockquote tag ready for display
$page->content .= $bible->parseVerse('Psalms 23');

// This changes the bible translation to the New Revised Standard Version
// This translation may not be available
$bible->setTranslation('nrsv');

// This returns the selected verses in a blockquote tag ready for display
$page->content .= $bible->parseVerse('Psalms 23');

// This demonstrates what happens when you try to load a translation you
// don't have installed
$bible->setTranslation('xyz');

// This returns the selected verses in a blockquote tag ready for display
$page->content .= $bible->parseVerse('Psalms 23');

// Because of the site (approx 5MB) of the bible XML file, you will want
// to free the object as soon as possible
unset($bible);
?>

Here is how that code looks when it is run:

1The LORD is my shepherd; I shall not want. 2He maketh me to lie down in green pastures: he leadeth me beside the still waters. 3He restoreth my soul: he leadeth me in the paths of righteousness for his name's sake. 4Yea, though I walk through the valley of the shadow of death, I will fear no evil: for thou art with me; thy rod and thy staff they comfort me. 5Thou preparest a table before me in the presence of mine enemies: thou anointest my head with oil; my cup runneth over. 6Surely goodness and mercy shall follow me all the days of my life: and I will dwell in the house of the LORD for ever.
Psalms 23 (KJV)
1The Lord is my shepherd, I shall not want. 2He makes me lie down in green pastures; he leads me beside still waters; 3he restores my soul. He leads me in right paths for his name's sake. 4Even though I walk through the darkest valley, I fear no evil; for you are with me; your rod and your staff- they comfort me. 5You prepare a table before me in the presence of my enemies; you anoint my head with oil; my cup overflows. 6Surely goodness and mercy shall follow me all the days of my life, and I shall dwell in the house of the Lord my whole life long.
Psalms 23 (NRSV)
Bible version XYZ unavailable

Here is the Bible object source code. It may run out to the right a bit.


<?php
/*
##################################################
#
# Filename..........: $RCSfile: Bible.php,v $
# Original Author...: Anthony L. Awtrey
# Version...........: $Revision: 0.1 $
# Last Modified By..: $Author: aawtrey $
# Last Modified.....: $Date: 2006/09/21 09:34:00 $
#
# Copyright 2006 Anthony Awtrey
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
*/

/*
 * This class provides the methods to load and query translations of the
 * Bible stored in XML.
 */
class Bible {

  var 
$error;
  var 
$translation;
  var 
$bible;
  var 
$verse = array( );
  var 
$books = array(
    
'genesis'            => 'Genesis',
    
'gen'                => 'Genesis',
    
'gn'                 => 'Genesis',
    
'g'                  => 'Genesis',
    
'exodus'             => 'Exodus',
    
'ex'                 => 'Exodus',
    
'exo'                => 'Exodus',
    
'exod'               => 'Exodus',
    
'leviticus'          => 'Leviticus',
    
'lev'                => 'Leviticus',
    
'lv'                 => 'Leviticus',
    
'numbers'            => 'Numbers',
    
'n'                  => 'Numbers',
    
'nu'                 => 'Numbers',
    
'num'                => 'Numbers',
    
'deuteronomy'        => 'Deuteronomy',
    
'd'                  => 'Deuteronomy',
    
'dt'                 => 'Deuteronomy',
    
'deut'               => 'Deuteronomy',
    
'joshua'             => 'Joshua',
    
'josh'               => 'Joshua',
    
'judges'             => 'Judges',
    
'judg'               => 'Judges',
    
'jdgs'               => 'Judges',
    
'ruth'               => 'Ruth',
    
'1 sam'              => '1 Samuel',
    
'1sam'               => '1 Samuel',
    
'i samuel'           => '1 Samuel',
    
'isamuel'            => '1 Samuel',
    
'1 samuel'           => '1 Samuel',
    
'1samuel'            => '1 Samuel',
    
'ii samuel'          => '2 Samuel',
    
'iisamuel'           => '2 Samuel',
    
'2 sam'              => '2 Samuel',
    
'2sam'               => '2 Samuel',
    
'2 samuel'           => '2 Samuel',
    
'2samuel'            => '2 Samuel',
    
'i kings'            => '1 Kings',
    
'ikings'             => '1 Kings',
    
'1 kings'            => '1 Kings',
    
'1kings'             => '1 Kings',
    
'1 kgs'              => '1 Kings',
    
'1kgs'               => '1 Kings',
    
'ii kings'           => '2 Kings',
    
'iikings'            => '2 Kings',
    
'2 kings'            => '2 Kings',
    
'2kings'             => '2 Kings',
    
'2 kgs'              => '2 Kings',
    
'2kgs'               => '2 Kings',
    
'i chronicles'       => '1 Chronicles',
    
'ichronicles'        => '1 Chronicles',
    
'1 chronicles'       => '1 Chronicles',
    
'1chronicles'        => '1 Chronicles',
    
'ii chronicles'      => '2 Chronicles',
    
'iichronicles'       => '2 Chronicles',
    
'2 chronicles'       => '2 Chronicles',
    
'2chronicles'        => '2 Chronicles',
    
'ezra'               => 'Ezra',
    
'ezr'                => 'Ezra',
    
'nehemiah'           => 'Nehemiah',
    
'neh'                => 'Nehemiah',
    
'esther'             => 'Esther',
    
'ester'              => 'Esther',
    
'esth'               => 'Esther',
    
'job'                => 'Job',
    
'psalms'             => 'Psalms',
    
'psalm'              => 'Psalms',
    
'psm'                => 'Psalms',
    
'pss'                => 'Psalms',
    
'ps'                 => 'Psalms',
    
'p'                  => 'Psalms',
    
'proverbs'           => 'Proverbs',
    
'prov'               => 'Proverbs',
    
'ecclesiastes'       => 'Ecclesiastes',
    
'qoheleth'           => 'Ecclesiastes',
    
'song of solomon'    => 'Song of Solomon',
    
'song of songs'      => 'Song of Solomon',
    
'solomon'            => 'Song of Solomon',
    
'song'               => 'Song of Solomon',
    
'sng'                => 'Song of Solomon',
    
'sos'                => 'Song of Solomon',
    
'isaiah'             => 'Isaiah',
    
'isa'                => 'Isaiah',
    
'isaiah'             => 'Isaiah',
    
'jeremiah'           => 'Jeremiah',
    
'jer'                => 'Jeremiah',
    
'lamentations'       => 'Lamentations',
    
'lam'                => 'Lamentations',
    
'ezekiel'            => 'Ezekiel',
    
'ezek'               => 'Ezekiel',
    
'ezk'                => 'Ezekiel',
    
'dan'                => 'Daniel',
    
'daniel'             => 'Daniel',
    
'hosea'              => 'Hosea',
    
'hos'                => 'Hosea',
    
'joel'               => 'Joel',
    
'jol'                => 'Joel',
    
'amos'               => 'Amos',
    
'obadiah'            => 'Obadiah',
    
'jonah'              => 'Jonah',
    
'micah'              => 'Micah',
    
'nahum'              => 'Nahum',
    
'nam'                => 'Nahum',
    
'habakkuk'           => 'Habakkuk',
    
'hab'                => 'Habakkuk',
    
'zephaniah'          => 'Zephaniah',
    
'zeph'               => 'Zephaniah',
    
'haggai'             => 'Haggai',
    
'hag'                => 'Haggai',
    
'zechariah'          => 'Zechariah',
    
'zachariah'          => 'Zechariah',
    
'malachi'            => 'Malachi',
    
'mal'                => 'Malachi',
    
'matthew'            => 'Matthew',
    
'matt'               => 'Matthew',
    
'ma'                 => 'Matthew',
    
'mt'                 => 'Matthew',
    
'mark'               => 'Mark',
    
'mk'                 => 'Mark',
    
'mrk'                => 'Mark',
    
'luke'               => 'Luke',
    
'lk'                 => 'Luke',
    
'l'                  => 'Luke',
    
'john'               => 'John',
    
'jhn'                => 'John',
    
'jn'                 => 'John',
    
'jo'                 => 'John',
    
'j'                  => 'John',
    
'acts'               => 'Acts',
    
'romans'             => 'Romans',
    
'rom'                => 'Romans',
    
'i corinthians'      => '1 Corinthians',
    
'icorinthians'       => '1 Corinthians',
    
'1 corinthians'      => '1 Corinthians',
    
'1corinthians'       => '1 Corinthians',
    
'1 cor'              => '1 Corinthians',
    
'1cor'               => '1 Corinthians',
    
'i c'                => '1 Corinthians',
    
'ic'                 => '1 Corinthians',
    
'1 c'                => '1 Corinthians',
    
'1c'                 => '1 Corinthians',
    
'ii corinthians'     => '2 Corinthians',
    
'iicorinthians'      => '2 Corinthians',
    
'2 corinthians'      => '2 Corinthians',
    
'2corinthians'       => '2 Corinthians',
    
'2 cor'              => '2 Corinthians',
    
'2cor'               => '2 Corinthians',
    
'ii c'               => '2 Corinthians',
    
'iic'                => '2 Corinthians',
    
'2 c'                => '2 Corinthians',
    
'2c'                 => '2 Corinthians',
    
'galatians'          => 'Galatians',
    
'gal'                => 'Galatians',
    
'ephesians'          => 'Ephesians',
    
'eph'                => 'Ephesians',
    
'e'                  => 'Ephesians',
    
'philippians'        => 'Philippians',
    
'philip'             => 'Philippians',
    
'phil'               => 'Philippians',
    
'php'                => 'Philippians',
    
'colossians'         => 'Colossians',
    
'col'                => 'Colossians',
    
'c'                  => 'Colossians',
    
'1 thess'            => '1 Thessalonians',
    
'1thess'             => '1 Thessalonians',
    
'i thessalonians'    => '1 Thessalonians',
    
'ithessalonians'     => '1 Thessalonians',
    
'1 thessalonians'    => '1 Thessalonians',
    
'1thessalonians'     => '1 Thessalonians',
    
'ii thessalonians'   => '2 Thessalonians',
    
'iithessalonians'    => '2 Thessalonians',
    
'2 thessalonians'    => '2 Thessalonians',
    
'2thessalonians'     => '2 Thessalonians',
    
'2 thess'            => '2 Thessalonians',
    
'2thess'             => '2 Thessalonians',
    
'1tim'               => '1 Timothy',
    
'1 tim'              => '1 Timothy',
    
'i timothy'          => '1 Timothy',
    
'itimothy'           => '1 Timothy',
    
'1 timothy'          => '1 Timothy',
    
'1timothy'           => '1 Timothy',
    
'ii timothy'         => '2 Timothy',
    
'iitimothy'          => '2 Timothy',
    
'2 tim'              => '2 Timothy',
    
'2tim'               => '2 Timothy',
    
'2 timothy'          => '2 Timothy',
    
'2timothy'           => '2 Timothy',
    
'titus'              => 'Titus',
    
'philemon'           => 'Philemon',
    
'phlm'               => 'Philemon',
    
'phm'                => 'Philemon',
    
'hebrews'            => 'Hebrews',
    
'heb'                => 'Hebrews',
    
'h'                  => 'Hebrews',
    
'james'              => 'James',
    
'jas'                => 'James',
    
'i peter'            => '1 Peter',
    
'ipeter'             => '1 Peter',
    
'i ptr'              => '1 Peter',
    
'iptr'               => '1 Peter',
    
'1 peter'            => '1 Peter',
    
'1peter'             => '1 Peter',
    
'1 ptr'              => '1 Peter',
    
'1ptr'               => '1 Peter',
    
'ii peter'           => '2 Peter',
    
'iipeter'            => '2 Peter',
    
'ii ptr'             => '2 Peter',
    
'iiptr'              => '2 Peter',
    
'2 peter'            => '2 Peter',
    
'2peter'             => '2 Peter',
    
'2 ptr'              => '2 Peter',
    
'2ptr'               => '2 Peter',
    
'ii peter'           => '2 Peter',
    
'i john'             => '1 John',
    
'ijohn'              => '1 John',
    
'1 john'             => '1 John',
    
'1john'              => '1 John',
    
'i jn'               => '1 John',
    
'ijn'                => '1 John',
    
'1 jn'               => '1 John',
    
'1jn'                => '1 John',
    
'ii john'            => '2 John',
    
'iijohn'             => '2 John',
    
'2 john'             => '2 John',
    
'2john'              => '2 John',
    
'ii jn'              => '2 John',
    
'iijn'               => '2 John',
    
'2 jn'               => '2 John',
    
'2jn'                => '2 John',
    
'iii john'           => '3 John',
    
'iiijohn'            => '3 John',
    
'3 john'             => '3 John',
    
'3john'              => '3 John',
    
'iii jn'             => '3 John',
    
'iiijn'              => '3 John',
    
'3 jn'               => '3 John',
    
'3jn'                => '3 John',
    
'jude'               => 'Jude',
    
'revelation of john' => 'Revelation of John',
    
'revelations'        => 'Revelation of John',
    
'revelation'         => 'Revelation of John',
    
'rev'                => 'Revelation of John'
  
);
  var 
$chapters = array(
    
'Genesis'            => array(31252426322224222932,
                                  
32201824211627333818,
                                  
34242067343546223543,
                                  
55322031294336302323,
                                  
57383434283431223326),
    
'Exodus'             => array(22252231233025323529,
                                  
10512231273616272526,
                                  
36313318403721434638,
                                  
18352335353829314338),
    
'Leviticus'          => array(17161735193038362420,
                                  
47,  85957333416303727,
                                  
24334423554634),
    
'Numbers'            => array(54345149312789262336,
                                  
35163345415013322229,
                                  
35413025186523314016,
                                  
544256293413),
    
'Deuteronomy'        => array(46372949332526202922,
                                  
32321829232220222120,
                                  
23302522191926682920,
                                  
30522912),
    
'Joshua'             => array(18241724152726352743,
                                  
232433156310182851,  9,
                                  
45341633),
    
'Judges'             => array(36233124314025355718,
                                  
40152520203113313048,
                                  
25),
    
'Ruth'               => array(22231822),
    
'1 Samuel'           => array(28362122122117222727,
                                  
15252352352358302442,
                                  
15232922442512251131,
                                  
13),
    
'2 Samuel'          => array(27323912252329181319,
                                  
27313933372329334326,
                                  
22513925),
    
'1 Kings'            => array(53462834183851662829,
                                  
43333431343424462143,
                                  
2953),
    
'2 Kings'           => array(18252744273320293736,
                                  
21212529382041373721,
                                  
2620372030),
    
'1 Chronicles'       => array(54552443268140404414,
                                  
474014172943271719,  8,
                                  
301932313132342130),
    
'2 Chronicles'       => array(17181722144222183119,
                                  
23162215191419341137,
                                  
201221272823,  9273627,
                                  
213325332723),
    
'Ezra'               => array(11701324172228361544),
    
'Nehemiah'           => array(11203223191973183839,
                                  
364731),
    
'Esther'             => array(222315171414101732,  3),
    
'Job'                => array(22132621273021223522,
                                  
20252822352216212929,
                                  
34301725,  61423282531,
                                  
40223337163324413024,
                                  
3417),
    
'Psalms'             => array( 612,  8,  8121017,  92018,
                                   
7,  8,  6,  7,  511155014,  9,
                                  
1331,  610221214,  91112,
                                  
24112222281240221317,
                                  
1311,  5261711,  9142023,
                                  
19,  9,  6,  7231311111712,
                                   
81211101320,  73536,  5,
                                  
24202823101220721319,
                                  
16,  818121317,  7185217,
                                  
1615,  523111312,  9,  9,  5,
                                   
82822354548431331,  7,
                                  
1010,  9,  81819,  2291767,
                                   
8,  9,  4,  8,  5,  6,  5,  6,  8,  8,
                                   
318,  3,  32126,  9,  82413,
                                  
10,  7121521102014,  9,  6),
    
'Proverbs'           => array(33223527233527361832,
                                  
31282535333328242930,
                                  
31293534282827282733,
                                  
31),
    
'Ecclesiastes'       => array(18262216201229171820,
                                  
1014),
    
'Song of Solomon'    => array(1717111616131314),
    
'Isaiah'             => array(312226,  6301325222134,
                                  
16,  62232,  91414,  725,  6,
                                  
17251823122113292433,
                                   
920241710223822,  831,
                                  
29252828251315222611,
                                  
23151217131221142122,
                                  
111219122524),
    
'Jeremiah'           => array(19372531313034222625,
                                  
23172722212127231518,
                                  
14304010382422173224,
                                  
40442622193221281816,
                                  
18221330,  528,  7473946,
                                  
6434),
    
'Lamentations'       => array(2222662222),
    
'Ezekiel'            => array(28102717171427181122,
                                  
25282323,  86324321449,
                                  
32314927172136262126,
                                  
18323331153828232949,
                                  
2620273125242335),
    
'Daniel'             => array(21493037312828272721,
                                  
4513),
    
'Hosea'              => array(1123,  519151116141715,
                                  
1214169),
    
'Joel'               => array(203221),
    
'Amos'               => array(151615132714171415),
    
'Obadiah'            => array(21),
    
'Jonah'              => array(17101011),
    
'Micah'              => array(16131213151620),
    
'Nahum'              => array(151319),
    
'Habakkuk'           => array(172019),
    
'Zephaniah'          => array(181520),
    
'Haggai'             => array(1523),
    
'Zechariah'          => array(21131014111514231712,
                                  
1714921),
    
'Malachi'            => array(1417186),
    
'Matthew'            => array(2523172548342934384230,
                                  
5058363928273530344646,
                                  
395146756620),
    
'Mark'               => array(4528354143563738505233,
                                  
4437724720),
    
'Luke'               => array(8052384439495056624254,
                                  
5935353231374348473871,
                                  
5653),
    
'John'               => array(51253654477153594142,
                                  
5750383127332640423125),
    
'Acts'               => array(26472637421560404348,
                                  
30255228414034284138,
                                  
4030352727324431),
    
'Romans'             => array(32293125212325393321,
                                  
362114233327),
    
'1 Corinthians'      => array(31162321132040132733,
                                  
343113405824),
    
'2 Corinthians'      => array(24171818211816241518,
                                  
332114),
    
'Galatians'          => array(242129312618),
    
'Ephesians'          => array(232221323324),
    
'Philippians'        => array(30302123),
    
'Colossians'         => array(29232518),
    
'1 Thessalonians'    => array(1020131828),
    
'2 Thessalonians'    => array(121718),
    
'1 Timothy'          => array(201516162521),
    
'2 Timothy'          => array(18261722),
    
'Titus'              => array(161515),
    
'Philemon'           => array(25),
    
'Hebrews'            => array(14181916142028132839,
                                  
402925),
    
'James'              => array(2726181720),
    
'1 Peter'            => array(2525221914),
    
'2 Peter'            => array(212218),
    
'1 John'             => array(1029242121),
    
'2 John'             => array(13),
    
'3 John'             => array(14),
    
'Jude'               => array(25),
    
'Revelation of John' => array(20292211141717132111,
                                  
19171820,  82118242115,
                                  
2721)
  );

  
/*
   * Class initialization (Default: King James Version)
   */
  
function  __construct($translation='niv') {
    global 
$_SERVER;
    global 
$_SESSION;
    global 
$_REQUEST;
    global 
$_POST;
    global 
$_GET;
    return 
$this->setTranslation($translation);
  }

  function 
__destruct()
  {
  }

  
/*
   * Loads a bible translation
   */
  
function setTranslation($translation) {
    
$this->translation $translation;
    if ( 
is_file(constant("RELPATH").'include/bibles/'.$translation.'.xml') ) {
      
$this->bible = @simplexml_load_file(constant("RELPATH").'include/bibles/'.$translation.'.xml');
      return(
true);
    } else {
      
$this->bible false;
      return(
false);
    }
  }

  
/*
   * Retuns the current translation
   */
  
function getTranslation() {
    return(
$this->translation);
  }

  
/*
   * Set the current book
   */
  
function setBook($book='') {
    if ( 
$book == '' ) { $this->error '<blockquote>You must specify the book you want to read.</blockquote>'; return(false); }
    if ( isset(
$this->books[strtolower($book)]) ) {
      
$this->verse['book'] = $this->books[strtolower($book)];
      return(
true);
    } else {
      
$this->error '<blockquote>Unknown Bible book reference: '.$book.'</blockquote>';
      return(
false);
    }
  }

  
/*
   * Get the current book
   */
  
function getBook() {
    return(
$this->verse['book']);
  }

  
/*
   * Set the current chapter
   */
  
function setChapter($chapter='') {
    if ( 
$chapter == '' ) { $this->error '<blockquote>Please specify at least one chapter in '.$this->getBook().' you want to read.</blockquote>'; return(false); }
    if ( isset(
$this->chapters[$this->getBook()][$chapter-1]) ) {
      
$this->verse['chapter'] = $chapter;
      return(
true);
    } else {
      
$this->error '<blockquote>Invalid Bible chapter reference. '.$this->getBook().' only contains '.count($this->chapters[$this->getBook()]).' chapters</blockquote>';
      return(
false);
    }
  }

  
/*
   * Get the current chapter
   */
  
function getChapter() {
    return(
$this->verse['chapter']);
  }

  
/*
   * Set the raw verse string
   */
  
function setVerses($verses='') {
    if ( 
$verses == '' ) { return(true); }
    
$this->verse['verses'] = $verses;
    return(
true);
  }

  
/*
   * Get the raw verse string
   */
  
function getVerses() {
    return(
$this->verse['verses']);
  }

  
/*
   * Set the current starting verse
   */
  
function setStart($start='') {
    if ( 
$start == '' ) { return(true); }
    if ( 
$start && $start <= $this->chapters[$this->getBook()][$this->getChapter()-1] ) {
      
$this->verse['start'] = $start;
      return(
true);
    } else {
      
$this->error '<blockquote>Invalid starting verse reference. Chapter only contains '.$this->chapters[$this->getBook()][$this->getChapter()-1].' verses</blockquote>';
      return(
false);
    }
  }

  
/*
   * Get the current starting verse
   */
  
function getStart() {
    return(
$this->verse['start']);
  }

  
/*
   * Set the current ending verse
   */
  
function setEnd($end='') {
    if ( 
$end == '' && $this->getStart() == '' ) {
      
$this->verse['start'] = 1;
      
$this->verse['end']   = 176;
      return(
true);
    }
    if ( 
$end == '' && is_int($this->getStart()) && $this->getStart() > ) {
      
$this->verse['end']   = $this->getStart();
      return(
true);
    }
    if ( 
$end && $end <= $this->chapters[$this->getBook()][$this->getChapter()-1] ) {
      
$this->verse['end'] = $end;
      return(
true);
    }
    
$this->error '<blockquote>Invalid ending verse reference. Chapter only contains '.$this->chapters[$this->getBook()][$this->getChapter()-1].' verses</blockquote>';
    return(
false);
  }

  
/*
   * Get the current ending verse
   */
  
function getEnd() {
    return(
$this->verse['end']);
  }

  
/*
   * Build an array of the number => verse to use to generate the HTML representation of the verse
   */
  
function setHtml($book,$chapter,$verses='') {
    
$this->setVerses($verses);
    
// This will loop over components of the verse using commas to delimit
    
foreach ( explode(','$verses) as $verse ) {
      
// Determine if the verse reference is a "1-2" or a "1" or no reference
      
if ( preg_match"/s*(d+)s*[-|–]+s*(d+).*/"$verse$v ) ) {
        
$start $v[1]; $end $v[2];
      } elseif ( 
preg_match"/s*(d+).*/"$verse$v ) ) {
        
$start $v[1]; $end $v[1];
      } else {
        
$start ''$end '';
      }
      
// Try to find the verses for this loop
      
if ( $this->setBook($book) && $this->setChapter($chapter) && $this->setStart($start) && $this->setEnd($end) ) {
        
$xpath   "//book[@name='".$this->getBook()."']/chapter[@name='".$this->getChapter().
                   
"']/verse[@name>='".$this->getStart()."' and @name<='".$this->getEnd()."']";
        foreach ( 
$this->bible->xpath($xpath) as $text) {
          
// This builds the array we will use to generate the verse html text.
          // It uses the verse number as the key of the array to prevent duplicate lines
          
$this->verse['html']["{$text['name']}"] = "$text";
        }
      } else {
        
// Don't set an error here because if we have an error from setting book/chapter/verse
        // it will be passed up from here
        
return(false);
      }
    }
    return(
true);
  }

  
/*
   * Generate html based on the array of verses
   */
  
function getHtml() {
    
$result  "<blockquote>n";
    
// Sort the verses based on verse number
    
ksort($this->verse['html']);
    
// Iterate over our verse set to generate the html
    
foreach ($this->verse['html'] as $key => $val) {
      
$result .= '<sup>'.$key.'</sup>'.$val."n";
    }
    
$result .= "<br />n";
    
$result .= '<i>'.$this->getBook().' '.$this->getChapter();
    if ( 
$this->getVerses() != '' ) {
      
$result .= ':'.$this->getVerses();
    }
    
$result .= ' ('.strtoupper($this->getTranslation()).")";
    
$result .= "</i>n";
    
$result .= "</blockquote>n";
    return(
$result);
  }

  
/*
   * Reset the current verse
   */
  
function resetVerse()
  {
    
$this->verse = array( 'book'    => false,
                          
'chapter' => false,
                          
'verses'  => false,
                          
'start'   => '',
                          
'end'     => '',
                          
'html'    => array() );
    return(
true);
  }

  
/*
   * Set the current verse from a bible verse string
   */
  
function setVerse($string)
  {
    
$this->resetVerse();
    if ( ! 
$this->bible ) {
      
$this->error '<blockquote>Bible version '.strtoupper($this->getTranslation()).' unavailable</blockquote>';
      return(
false);
    }
    if ( 
preg_match"/^s*([dIi]*s*[p{L}p{Z}]+).?s*(d*)s*[:]*s*([ds,-–]*).*$/"$string$v) ) {
      return( 
$this->setHtml(trim($v[1]),$v[2],$v[3]) );
    } else {
      
$this->error '<blockquote>Unknown Bible scripture reference: '.$string.'</blockquote>';
      return(
false);
    }
  }

  
/*
   * Returns formatted HTML for a given range of verses for this translation
   */
  
function getVerse()
  {
    return(
$this->getHtml());
  }

  
/*
   * Takes a free-form verse designation as an input and returns the verse
   */
  
function parseVerse($string)
  {
    if ( 
$this->setVerse($string) ) {
      return(
$this->getVerse());
    } else {
      return(
$this->error);
    }
  }

}

?>