Location: PHPKode > projects > phpBible > phpbible/index.php
<?php

###
###
###    Copyright 2004, Danny Carlton. Permission is hereby granted to distribute 
###  copies of this software package as long as you do not charge for it, and the 
###  copyright notices remain intact. Permission is also granted to use the concepts 
###  in these scripts for other similar scripts, but you may not simply copy the scripts and claim them as your own.
###   
###

if(!$login)
  {
  reset ($HTTP_POST_VARS);
  while (list ($key, $val) = each ($HTTP_POST_VARS)) 
    {
    $$key=$value;
    }
  reset ($HTTP_GET_VARS);
  while (list ($key, $val) = each ($HTTP_GET_VARS)) 
    {
    $$key=$value;
    }
  }


$browser2 = getenv("HTTP_USER_AGENT");
$browser=str_replace(' ', '+', $browser);

if(stristr($browser2, 'netscape')){$browser='NS';}
if(stristr($browser2, 'mozilla')){$browser='NS';}
if(stristr($browser2, 'msie')){$browser='IE';}
if(stristr($browser2, 'opera')){$browser='OP';}

function getmicrotime(){ 
    list($usec, $sec) = explode(" ",microtime()); 
    return ((float)$usec + (float)$sec); 
    } 
srand(getmicrotime());
$pagestart=getmicrotime();

$rn  = rand(1, 9999);


if(!$begin){$begin=0;}
else{$begin--;}
require("./config.php");
if (!$db_name)
  {
  header("Location: install.php"); /* Redirect browser */
  exit;
  }
$link = mysql_connect($host, $user, $password)
    or die("Could not connect : " . mysql_error());
mysql_select_db($db_name) or die("Could not select database");


if($results_side=='left')
  {
  $results_marker='{{RESULTS LEFT}}';
  $results_marker_off='{{RESULTS RIGHT}}';
  }
else
  {
  $results_marker='{{RESULTS RIGHT}}';
  $results_marker_off='{{RESULTS LEFT}}';
  $lex_left='lex_x=((document.body.scrollWidth-640)/2)+20;';
  }


if($site_name){$sn="<a href=\"$main_url\">$site_name</a></b>&gt;&gt;<b>";}
$dir="<center><table border=0 style=\"align: left; margin-top: 0; margin-bottom: 0; width: 500;\"><tr><td><font face=\"Verdana\" size=\"1\"><b>$sn<a href=\"$script_name\">phpBible</a>";
if($keyword){$dir.="</b>&gt;&gt;<b>{{DISPLAY}}</b></font>";}
$dir.='</td></tr></table></center>';
$html_template=implode('', file("./_template_main.htm"));
$script_insert="<script>
lex_div.style.display='none'; 
lex_shadow1.style.display='none'; 
lex_shadow2.style.display='none'
var old_wi=wi0;
</script>";
if($keyword){$html_template=str_replace('<!--script insert -->', $script_insert, $html_template);}
#if($browser!='IE'){$html_template=str_replace('<sup>?</sup>', '', $html_template);}
$html_template=str_replace('phpBible.css', "phpBible.css?$rn", $html_template);
$html_template=str_replace('{{HEADING}}', "{{HEADING}}$dir", $html_template);
$html_template=str_replace('<title>phpBible.org</title>', "<title>$site_name::phpBible</title>", $html_template);
$html_template=str_replace('{{script_name}}', $script_name, $html_template);
$html_template=str_replace('{{HEADING}}', implode('', file('_template_heading.htm')), $html_template);
$html_template=str_replace('{{FOOTER}}', implode('', file('_template_footer.htm')), $html_template);
if($keyword)
  {
  $html_template=str_replace($results_marker_off, implode('', file('_template_custom2.htm')), $html_template);
  }
else
  {
  $html_template=str_replace($results_marker_off, implode('', file('_template_custom.htm')), $html_template);
  $html_template=str_replace('{{site_name}}', $site_name, $html_template);
  $html_template=str_replace('{{main_url}}', $main_url, $html_template);
  $html_template=str_replace('{{script_name}}', $script_name, $html_template);
  $html_template=str_replace('{{domain}}', $domain, $html_template);
  $html_template=str_replace('{{path}}', $path, $html_template);
  $html_template=str_replace($results_marker, implode('', file('_template_custom3.htm')), $html_template);
  }
$html_template=str_replace('{{VERY DARK}}', $page_very_dark, $html_template);
$html_template=str_replace('{{DARK}}', $page_dark, $html_template);
$html_template=str_replace('{{LIGHT}}', $page_light, $html_template);
$html_template=str_replace('{{MEDIUM}}', $page_medium, $html_template);
$html_template=str_replace('{{MAIN}}', $script_name, $html_template);
if($lex_left){$html_template=str_replace('lex_x=((document.body.scrollWidth-640)/2)+340;', $lex_left, $html_template);}

if($p_display=='par')
  {
  $html_template=str_replace('value="trad" name="p_display" checked', 'value="trad" name="p_display"', $html_template);
  $html_template=str_replace('value="par" name="p_display"', 'value="par" name="p_display" checked', $html_template);
  }

if(!$keyword)
  {
  $html_template=str_replace($results_marker, "<span id=\"wi0\" name=\"wi0\"></span>", $html_template);
  }
else
  {
#echo "original: $keyword<br>\n";
$original_keyword=$keyword;
$keyword=ereg_replace('^ +', '', $keyword);
  $keyword=str_replace('.', '', $keyword);
$keyword=str_replace('1st ', '1 ', $keyword);
$keyword=str_replace('2nd ', '2 ', $keyword);
$keyword=str_replace('3rd ', '3 ', $keyword);
  if(ereg("[0-9]", $keyword))
    {
#echo "number found<br>\n";
  $keyword=eregi_replace("^i ", "1 ", $keyword);
  $keyword=eregi_replace("^ii ", "2 ", $keyword);
  if(ereg('^1[a-zA-Z]', $keyword))
    {
#echo "screwed up 1 found!<br>\n";
    $keyword=eregi_replace("^1", '1 ', $keyword);
    }
  if(ereg("^2[a-zA-Z]", $keyword))
    {
    $keyword=eregi_replace("^2", '2 ', $keyword);
    }
  if(ereg("^3[a-zA-Z]", $keyword))
    {
    $keyword=eregi_replace("^3", '3 ', $keyword);
    }
#echo "modified: $keyword<br>";
    $p_key=$keyword;
    $p_key=ereg_replace(" +", ' ', $p_key);
    $p_keys=explode(' ', $p_key);
#echo "0:$p_keys[0]|1:$p_keys[1]<br>\n";
    if(!$p_keys[0])
      {
#echo "no pk[0]<br>";
      $p_keys[0]=$p_keys[1];
      $p_keys[1]=$p_keys[2];
      $p_keys[2]=$p_keys[3];
      $p_keys[3]='';
      }
    if(ereg("[0-9]", $p_keys[0]))
      {
      $p_keys[0]=ereg_replace("[^0-9]", '', $p_keys[0]);
      $p_keys[0]="$p_keys[0] $p_keys[1]";
      $p_keys[1]="$p_keys[2] $p_keys[3]";
      $p_keys[2]='';
#echo "keys: $p_keys[0]|$p_keys[1]|$p_keys[2]|<br>\n";
      }
    if(ereg("[0-9]", $p_keys[1]))
      {
      $p_key2=implode(' ', $p_keys);
      $p_key2=str_replace($p_keys[0], '', $p_key2);
      $reference_key=ereg_replace("[^0-9:,-]", '', $p_key2);
      $book_key=$p_keys[0];
      }
    $keyword_v="$book_key $reference_key";
#echo $keyword_v;
    }
  if((strstr(" $keyword", '#')) or (strstr(" $keyword", '~')))
    {
#echo "search by strong's<br>\n";
    $st_key=str_replace('#', '', $keyword);
    $st_key=str_replace('~', '', $st_key);
    $st_key=ereg_replace(" +", '', $st_key);
    }
  $keyword=str_replace("'s", '×', $keyword);
  $keyword=ereg_replace("[^a-zA-Z *×\"]", '', $keyword);
  $keyword=str_replace('×', "'s", $keyword);
  $keyword=str_replace('"', '&quot;', $keyword);
  if($keyword_v){$keyword=$keyword_v;}
  if($st_key){$keyword="#$st_key";}
  $keyword=eregi_replace("^Psalms ", "Psalm ", $keyword);
  $html_template=str_replace('<input type="text" name="keyword" size="20"', "<input value=\"$keyword\" type=\"text\" name=\"keyword\" size=\"20\"", $html_template);
  $keyword=str_replace('&quot;', '"', $keyword);
  $keyword=str_replace("'s", "\\'s", $keyword);
  $keyword_d=str_replace("\\'s", "'s", $keyword);
  }

##### check wordcount.dat

$wordcount=file("./wordcount.dat");
for($i=0;$i<count($wordcount);$i++)
  {
  $wc_a=explode(', ', $wordcount[$i]);
  $ws=str_replace("\n", '', $wc_a[2]);
  $ws=str_replace("\r", '', $ws);
  $wt=str_replace('\\', '', $wc_a[0]);
#echo "|$keyword|--|$wt|<br>\n|$section|--|$ws|<br>\n";
  if (($keyword==$wt) and ($section==$ws))
    {
    $max_rows=str_replace("\n", '', $wc_a[1]);
    $wc_source='file';
    }
  }

$table_name=$table_prefix;
$table_name.='books';

$query = "SELECT * FROM $table_name";
$book_query = mysql_query($query) or die("Query failed : " . mysql_error());
while ($book_in = mysql_fetch_array($book_query, MYSQL_ASSOC))
  {
  $this_num=$book_in[number];
  $book[$this_num]=$book_in[book];
  $chapters[$this_num]=$book_in[chapters];
  $abbr[$this_num]=$book_in[abbr];
  $bc=10+$this_num;
  $book_choices.="                <option value=\"$bc\">$book_in[book]\n";
  }
mysql_free_result($book_query);

$html_template=str_replace('<option value="10">General Epistles', "<option value=\"10\">General Epistles\n                <option value=\"11\">-----------------------\n$book_choices", $html_template);

if($book_key)
  {
  for($i=1;$i<=count($book);$i++)
    {
    if(strtolower($book[$i])==strtolower($book_key)){$book_num=$i;}
    $ab=explode(', ', $abbr[$i]);
    for($a=0;$a<count($ab);$a++)
      {
      if(strtolower($ab[$a])==strtolower($book_key)){$book_num=$i;}
      }
    }
  }

$table_name=$table_prefix;
$table_name.='av';


$dbquerystart0=getmicrotime();

#echo "keyword=$keyword<br>\n";

$keyword2=str_replace('"', '|~~"~~|', $keyword);
$x_keys=explode('"', $keyword2);
for($i=0;$i<count($x_keys);$i++)
  {
  if((strstr($x_keys[$i], '~~|')) and (strstr($x_keys[$i], '|~~')))
    {
    $temp=str_replace('|~~', '', $x_keys[$i]);
    $temp=str_replace('~~|', '', $temp);
    if($search_key){$search_key.='&& ';}
    $search_key.="text REGEXP \"[^a-zA-Z]".$temp."[^a-zA-Z]\" ";
#    $search_key.="text REGEXP \"$temp\" ";
    }
  else
    {
    $temp="$x_keys[$i] ";
    $temp=str_replace('~~|', '', $temp);
    $keyword3.=str_replace('|~~', '', $temp);
    }
  }
$keyword3=rtrim($keyword3);
$keyword3=ltrim($keyword3);
if($keyword3)
  {
  if($search_key){$search_key.='&& ';}
  $keys=explode(' ', $keyword3);
  for($i=0;$i<count($keys);$i++)
    {
    if(strstr($keys[$i], '*'))
      {
      $alt_key=str_replace('*', '', $keys[$i]);
      $search_key.="(text REGEXP \"[^a-zA-Z]".$keys[$i]."\" || text REGEXP \"[^a-zA-Z]".$alt_key."[^a-zA-Z]\"|| text REGEXP \"^".$alt_key."[^a-zA-Z]\"|| text REGEXP \"^".$alt_key."\") ";
#      $search_key.="(text REGEXP \"[^a-zA-Z]".$keys[$i]."\" || text REGEXP \"^".$alt_key."\") ";
#      $search_key.="(text REGEXP \"$keys[$i]\" || text REGEXP \"$alt_key\") ";
      }
    else
      {
      $search_key.="(text REGEXP \"[^a-zA-Z]".$keys[$i]."[^a-zA-Z]\" || text REGEXP \"^$keys[$i]"."[^a-zA-Z]\")";
#      $search_key.="text REGEXP \"".$keys[$i]."[^a-zA-Z]\" || text REGEXP \"^$keys[$i]"."[^a-zA-Z]\"";
#    $search_key.="text REGEXP \"$keys[$i]\" ";
      }
    if($i<(count($keys)-1)){$search_key.='&& ';}
    }
  }
$keyword =str_replace('"', '\\"', $keyword);

#echo "$search_key<br>\n";


if($reference_key)
  {
  $book_name=str_replace('1 ', '1st ', $book[$book_num]);
  $book_name=str_replace('2 ', '2nd ', $book_name);
  $book_name=str_replace('3 ', '3rd ', $book_name);
  $book_name=eregi_replace("^Psalms", "Psalm", $book_name);
  $html_template=str_replace('{{DISPLAY}}', "passage display: $book_name $reference_key", $html_template);
  $html_template=str_replace("<input value=\"$keyword\"", "<input value=\"$book_name $reference_key\"", $html_template);
  }
else
  {
  $html_template=str_replace('{{DISPLAY}}', "word search: $keyword_d", $html_template);
  }

if($reference_key)
  {
  $working_ref=$reference_key;
  if(strstr($working_ref, ':'))
    {
    $temp_a=explode(':', $working_ref);
    $chapter=$temp_a[0];
    if(strstr($temp_a[1], ','))
      {
      $temp_b=explode(',', $temp_a[1]);
      for($i=0;$i<count($temp_b);$i++)
        {
        $verse_list.="verse = \"$temp_b[$i]\"";
        if($i<(count($temp_b)-1)){$verse_list.=' || ';}
        }
      $search_key="book = \"$book_num\" && chapter = \"$chapter\" && ($verse_list)";
      $max_rows=count($temp_b);
      }
    elseif(strstr($temp_a[1], '-'))
      {
      $temp_b=explode('-', $temp_a[1]);
      $verse_start=$temp_b[0];
      $verse_end=$temp_b[1];
      $search_key="book = \"$book_num\" && chapter = \"$chapter\" && verse >= \"$verse_start\" && verse <= \"$verse_end\"";
      $max_rows=$verse_start-$verse_end;
      }
    else
      {
      $search_key="book = \"$book_num\" && chapter = \"$chapter\" && verse = \"$temp_a[1]\"";
      }
    }
  else
    {
    $chapter=$working_ref;
    $search_key="book = \"$book_num\" && chapter = \"$chapter\"";
    #$max_rows=$cha50;
    }
  }

if($st_key){$search_key="coding REGEXP \"~$st_key~\" ";}

if($section)
  {
  if($section==1)
    {
    $search_key.="&& book < \"40\" ";
    $html_template=str_replace('<option value="1">Old Testament', '<option value="1" selected>Old Testament', $html_template);
    $section_searched="<br>in the Old Testament";
    }
  if($section==2)
    {
    $search_key.="&& book > \"39\" ";
    $html_template=str_replace('<option value="2">New Testament', '<option value="2" selected>New Testament', $html_template);
    $section_searched="<br>in the New Testament";
    }
  if($section==3)
    {
    $search_key.="&& book < \"6\" ";
    $html_template=str_replace('<option value="3">Books of Law', '<option value="3" selected>Books of Law', $html_template);
    $section_searched="<br>in the Books of Law";
    }
  if($section==4)
    {
    $search_key.="&& book > \"5\" && book < \"18\" ";
    $html_template=str_replace('<option value="4">Books of History', '<option value="4" selected>Books of History', $html_template);
    $section_searched="<br>in the Books of History";
    }
  if($section==5)
    {
    $search_key.="&& book > \"17\" && book < \"23\" ";
    $html_template=str_replace('<option value="5">Books of Poetry', '<option value="5" selected>Books of Poetry', $html_template);
    $section_searched="<br>in the Books of Poetry";
    }
  if($section==6)
    {
    $search_key.="&& book > \"22\" && book < \"28\" ";
    $html_template=str_replace('<option value="6">Major Prophets', '<option value="6" selected>Major Prophets', $html_template);
    $section_searched="<br>in the Major Prophets";
    }
  if($section==7)
    {
    $search_key.="&& book > \"27\" && book < \"40\" ";
    $html_template=str_replace('<option value="7">Minor Prophets', '<option value="7" selected>Minor Prophets', $html_template);
    $section_searched="<br>in the Minor Prophets";
    }
  if($section==8)
    {
    $search_key.="&& book > \"39\" && book < \"44\" ";
    $html_template=str_replace('<option value="8">The Gospels', '<option value="8" selected>The Gospels', $html_template);
    $section_searched="<br>in the The Gospels";
    }
  if($section==9)
    {
    $search_key.="&& book > \"44\" && book < \"59\" ";
    $html_template=str_replace('<option value="9">Pauline Epistles', '<option value="9" selected>Pauline Epistles', $html_template);
    $section_searched="<br>in the Pauline Epistles";
    }
  if($section==10)
    {
    $search_key.="&& book > \"58\" && book < \"66\" ";
    $html_template=str_replace('<option value="10">General Epistles', '<option value="10" selected>General Epistles', $html_template);
    $section_searched="<br>in the General Epistles";
    }
  if($section>10)
    {
    $this_book=$section-10;
    $search_key.="&& book = \"$this_book\" ";
    $html_template=str_replace("<option value=\"$section\">$book[$this_book]", "<option value=\"$section\" selected>$book[$this_book]", $html_template);
    $section_searched="<br>in $book[$this_book]";
    }
  }

$search_key=str_replace('*', '[a-zA-Z*]', $search_key);

#echo "keyword=$keyword<br>\nsearch key=$search_key<br>\n";

if(($search_key) and (!$max_rows) and (!$reference_key))
  {
  $query = "SELECT * FROM $table_name WHERE $search_key";
  $result = mysql_query($query) or die("Query failed : " . mysql_error());
  $max_rows = mysql_num_rows($result);
  $wordcount[]="$keyword, $max_rows, $section\n";
  $data=implode('', $wordcount);
  $fp = fopen("wordcount.dat", "w");
  fwrite ($fp, $data);
  fclose ($fp);
  $wc_source='mySQL';
  }
$page_max=20;
$verses_left=($max_rows)-$begin;

$dbqueryend0=getmicrotime();

$dbquerystart=getmicrotime();

if(!$book_key){$page_limit=" LIMIT ".$begin.', '.$page_max;}

#echo "mySQL: $search_key<br>\n";

$query = "SELECT * FROM $table_name WHERE $search_key$page_limit";
$keyword=$keyword_d;
if($search_key){$result = mysql_query($query) or die("Query failed : " . mysql_error());
$num_rows = mysql_num_rows($result);
if($reference_key){$max_rows = mysql_num_rows($result);}
$results .= "<p style=\"text-align: Justify\">";
$wi=0;
while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
  {
  $offset=0;
  $encoding=explode(' ', $line[coding]);


  $text_array=explode(' ', $line[text]);

  for($t=0;$t<count($text_array);$t++)
    {
    $text_array[$t]=str_replace("s'", "s", $text_array[$t]);
    $text_array[$t]=str_replace('LORD', 'L<small>ORD</small>', $text_array[$t]);
    $text_array[$t]=str_replace('L<small>ORD</small>\'S', 'L<small>ORD\'S</small>', $text_array[$t]);
    $text_array[$t]=str_replace('GOD', 'G<small>OD</small>', $text_array[$t]);
    $text_array[$t]=str_replace('JEHOVAH', 'J<small>EHOVAH</small>', $text_array[$t]);
    $text_array[$t]=str_replace('MENE', 'M<small>ENE</small>', $text_array[$t]);
    $text_array[$t]=str_replace('TEKEL', 'T<small>EKEL</small>', $text_array[$t]);
    $text_array[$t]=str_replace('UPHARSIN', 'U<small>UPHARSIN</small>', $text_array[$t]);
    $text_array[$t]=str_replace('PERES', 'P<small>ERES</small>', $text_array[$t]);
#    $text_array[$t]=str_replace('THE', 'T<small>HE</small>', $text_array[$t]);
#    $text_array[$t]=str_replace('OF', 'O<small>F</small>', $text_array[$t]);
#    $text_array[$t]=str_replace('KING', 'K<small>ING</small>', $text_array[$t]);
#    $text_array[$t]=str_replace('JEWS', 'J<small>EWS</small>', $text_array[$t]);
#    $text_array[$t]=str_replace('JESUS', 'J<small>ESUS</small>', $text_array[$t]);
#    $text_array[$t]=str_replace('BRANCH', 'B<small>RANCH</small>', $text_array[$t]);
    for($kw=0;$kw<count($keys);$kw++)
      {
      if(strstr($keys[$kw], '*'))
        {
        $this_key=str_replace('*', '[a-zA-Z*]', $keys[$kw]);
        $this_other_key=str_replace('*', '', $keys[$kw]);
        if(eregi($this_key, $text_array[$t]))
          {
          $text_array[$t]="<f>$text_array[$t]</f>";
          }
        if(eregi($this_other_key, $text_array[$t]))
          {
          $text_array[$t]="<f>$text_array[$t]</f>";
          }
        }
      else
        {
        $this_other_key=str_replace('*', '', $keys[$kw]);
        $this_word=eregi_replace("[^a-zA-Z]", '', $text_array[$t]);
        if((stristr($this_word, $this_other_key)) and (stristr($this_other_key, $this_word)))
          {
          $text_array[$t]="<f>$text_array[$t]</f>";
          }          
        }
      }
    }



  for($c=0;$c<count($encoding);$c++)
    {
    if(strstr($encoding[$c], '*'))
      {
      $e_data=explode('~', $encoding[$c]);
      $num=$e_data[0]+$offset;
      $text_array[$num]="° $text_array[$num]";
      $offset--;
      }
    }
  $new_line=implode(' ', $text_array);
  $text_array=explode(' ', $new_line);
  if(strstr($keyword, '"'))
    {
    $keyphrase=str_replace('"', '', $keyword);
    $keyphrase_array=explode(' ', $keyphrase);
    $keyphrase=str_replace('*', '[a-zA-Z*]', $keyphrase);
    $keywords=count($keyphrase_array);
    $quit=count($text_array)-$keywords;
    for($t=0;$t<=$quit;$t++)
      {
      $t2=$t+$keywords;
      $t1=$t+1;
      for($tp=1;$tp<=$keywords;$tp++){$tp2=$t+$tp; $test_phrase.="$text_array[$tp2] ";}
      if(eregi($keyphrase, $test_phrase)){$text_array[$t1]="<f>$text_array[$t1]"; $text_array[$t2]="$text_array[$t2]</f>";}
      $test_phrase='';
      }
    }
  $c_count=count($encoding)+$inv_word;
  for($c=0;$c<count($encoding);$c++)
    {
    if(strstr($encoding[$c], '~'))
      {
      $e_data=explode('~', $encoding[$c]);
      $word=$e_data[0];
      $word_1=$word-1;
      $key_p=$e_data[2];
      if(strstr($key_p, '*'))
        {
        $key_p=str_replace('*', '', $key_p);
        $text_array[$word_1]=str_replace("$key_p</span>", '</span>', $text_array[$word_1]);
        $e_data[2]="*$key_p";
        }
      $key_w=str_replace("'", "\\'", $text_array[$word]);
      $key_w=str_replace($e_data[2], '', $key_w);
      $key_w=str_replace('</i>', '', $key_w);
      $key_w=str_replace('<i>', '', $key_w);
      $key_w=str_replace('<f>', '', $key_w);
      $key_w=str_replace('</f>', '', $key_w);
      if(stristr($text_array[$word], '</i>'))
        {
        $text_array[$word]=str_replace('</i>', '', $text_array[$word]);
        $it2='</i>';
        }
      if(stristr($text_array[$word], '<f>'))
        {
        $text_array[$word]=str_replace('<f>', '', $text_array[$word]);
        $it1.='<f>';
        }
      if(stristr($text_array[$word], '</f>'))
        {
        $text_array[$word]=str_replace('</f>', '', $text_array[$word]);
        $it2.='</f>';
        }
      if((!$reference_key) and ($st_key==$e_data[1])){$text_array[$word]="<FONT style=\"BACKGROUND-COLOR: yellow\">$text_array[$word]</FONT>";}
      $key_w=str_replace('<small>', '', $key_w);
      $key_w=str_replace('</small>', '', $key_w);
      if($browser=='IE')
        {
        $text_array[$word]="$it1<span id=\"wi$wi\" name=\"wi$wi\" class=def onclick=\"show_def('$e_data[1]', '$key_w', this);\" onMouseOver=\"status='Strong\'s: #$e_data[1]'\" onMouseOut=\"status=''\">$text_array[$word]</span>$it2";
        $wi++;$it1='';$it2='';
        if($e_data[2])
          {
          $text_array[$word]=str_replace("$e_data[2]<", '<', $text_array[$e_data[0]]);
          $text_array[$word]=str_replace("$e_data[2]')", '\')', $text_array[$word]);
          $text_array[$word]="$text_array[$word]$e_data[2]";
#          $text_array[$word]="$text_array[$word]";
          $text_array[$word]=str_replace('>*', '>', $text_array[$word]);
          $text_array[$word]=str_replace('>,*', '>', $text_array[$word]);
          }
        }
      else
        {         
        $text_array[$word]="$it1<span class=\"def\" onMouseOver=\"status='Strong\'s: #$e_data[1]'\" onMouseOut=\"status=''\" style=\"cursor:pointer\" onclick=\"show_def2('$e_data[1]', '$key_w')\">$text_array[$word]</span>$it2";
        $wi++;$it1='';$it2='';
        if($e_data[2])
          {
          $text_array[$word]=str_replace("$e_data[2]<", '<', $text_array[$e_data[0]]);
          $text_array[$word]=str_replace("$e_data[2]')", '\')', $text_array[$word]);
          $text_array[$word]="$text_array[$word]$e_data[2]";
          $text_array[$word]=str_replace('>*', '>', $text_array[$word]);
          $text_array[$word]=str_replace('>,*', '>', $text_array[$word]);
          }
        }
      }
    if(strstr($encoding[$c], '['))
      {
      if(!$it){
      $temp=str_replace('[', '', $encoding[$c]);
      $temp=str_replace(']', '', $temp);
      $text_array[$temp]="<i>$text_array[$temp]";
      }
      else{
      $temp=str_replace('[', '', $encoding[$c]);
      $temp=str_replace(']', '', $temp);
      $text_array[$temp]="[$text_array[$temp]";}
      $it++;
      }
    if(strstr($encoding[$c], ']'))
      {
      $it--;
      if(!$it){
      $temp=str_replace('[', '', $encoding[$c]);
      $temp=str_replace(']', '', $temp);
      $text_array[$temp]="$text_array[$temp]</i>";}
      else{
      $temp=str_replace('[', '', $encoding[$c]);
      $temp=str_replace(']', '', $temp);
      $text_array[$temp]="$text_array[$temp]]";}
      }
    if(strstr($encoding[$c], '¶')){$text_array[0]="¶$text_array[0]";}
    }
  $verse=implode(' ', $text_array);
#  if(!$st_key)
  if(!$reference_key)
    {
    $verse=str_replace('<f>', '<FONT style="BACKGROUND-COLOR: yellow">', $verse);
    $verse=str_replace('</f>', '</FONT>', $verse);
    }
#  $verse="$verse\n";
  $this_book=$line[book];
  $book_name=$book[$this_book];
  if($book_name=='Psalms'){$book_name='Psalm';}
  if(!$reference_key)
    {
    $book_ref="$book_name $line[chapter]:";
    }
  if(($reference_key) and ($p_display=='par'))
    {
    $p_display_var='&p_display=par';
    if(strstr($verse, '¶'))
      {
      $verse=str_replace('¶', '', $verse);
      $results.= "<br>&nbsp;&nbsp;&nbsp; <font size=1><sup>$book_ref$line[verse]</sup></font>$verse ";
      }
    else
      {
      $results.= "<font size=1><sup>$book_ref$line[verse]</sup></font>$verse ";
      }
    }
  else
    {
    $verse=str_replace('¶', '', $verse);
    $ref_kw=str_replace(' ', '+', $book_ref);
    $ref_kw=str_replace(':', '', $ref_kw);
    $results.= "<b><a href=\"$script_name?keyword=$ref_kw\">$book_ref</a>$line[verse]</b> $verse<br>\n";
    }
  }
}
if(!$results){$results="<span id=\"wi0\" name=\"wi0\"></span>";}
$kw_st=$keyword;
if($st_key){$keyword=str_replace('#', '~', $keyword);}

$dbqueryend=getmicrotime();
$results.= "</p>";
mysql_close($link);
$next_r=$begin+21;
$last_r=$begin-19;
$end=$begin+20;
if($end>$max_rows){$end=$max_rows;}
$begin1=$begin+1;
$pages=ceil($max_rows/20);
$page_select_num=$pages;
$this_page=floor($begin/20)+1;
$page_start=1;
if($section){$section_link="&section=$section";}
$keyword=str_replace('"', '%22', $keyword);
$keyword_u=str_replace(' ', '+', $keyword);
$this_url="$domain/$path$script_name?keyword=$keyword_u$section_link";
#if($this_page>1){$this_url .= "&begin=$this_page";}
if($this_page>1){$url_begin=$begin+1; $this_url .= "&begin=$url_begin";}
if($p_display=='par'){$this_url .= "&p_display=$p_display";}
$this_url=str_replace('&', '&amp;', $this_url);
if(($this_page>5) and ($pages>10))
  {
  $page_start=$this_page-4;
  if(($pages-$this_page)<5){$page_start=$pages-9;}
  $i_page=(($page_start-2)*20)+1;
  $page_back="<a href=\"$script_name?keyword=$keyword&begin=$i_page$section_link\">&lt;&lt;</a> ";
  }

$page_end=$page_start+($pages-1);
if($page_end>($pages)){$page_end=$pages;}
if((($pages-$this_page)>5)  and ($pages>9))
  {
  $page_end=$page_start+9;
  $i_page=(($page_end)*20)+1;
  if($this_page<($pages-4)){$more="<a href=\"$script_name?keyword=$keyword&begin=$i_page$section_link\">&gt;&gt;</a>";}
  }
if($pages>1)
  {
  for($i=$page_start;$i<=$page_end;$i++)
    {
    if($i==$this_page){$page_select.="<b><font color=\"#cccccc\">$i</font></b> ";}
    else
      {
      $i_page=(($i-1)*20)+1;
      $page_select.="<a href=\"$script_name?keyword=$keyword&begin=$i_page$section_link\">$i</a> ";
      }
    }
  }

if(!$reference_key)
  {
  $max="<center><font face=\"Verdana\" size=\"1\">$begin1 - $end of $max_rows verses containing <b>$keyword_d</b>$section_searched.</font></center>";
  $select_page="<font face=\"verdana\" size=1>$page_back$page_select$more</font>";
  if($verses_left>20)
    {
    if($verses_left>40){$next_count=20;}
    else{$next_count=$verses_left-20;}
    $next_20="<b><font face=\"verdana\" size=2><a href=\"$script_name?keyword=$keyword&begin=$next_r$section_link\">next $next_count&gt;</a></font></b>";
    }
  if($begin){$last_20="<b><font face=\"verdana\" size=2><a href=\"$script_name?keyword=$keyword&begin=$last_r$section_link\">&lt;last 20</a></font></b>";}
  }

#######################################################################################
#######################################################################################


else
  {
  $ch_link=str_replace(' ', '+', "$book_name $chapter");
  $previous_chapter=$chapter-1;
  $previous_book=$book_name;
  if($previous_chapter<1){$previous_chapter=$chapters[$book_num-1]; $previous_book=$book[$book_num-1];}
  $p_ref="$previous_book $previous_chapter";
  $p_ref=str_replace(' ', '+', $p_ref);

  $next_chapter=$chapter+1;
  $next_book=$book_name;
  if($next_chapter>$chapters[$book_num]){$next_chapter=1; $next_book=$book[$book_num+1];}
  $n_ref="$next_book $next_chapter";
  $n_ref=str_replace(' ', '+', $n_ref);

  $max="<a href=\"?keyword=$p_ref$p_display_var\"><font size=\"1\" face=\"Verdana\">&lt;&lt; </font></a> <font size=4><b><a href=\"?keyword=$ch_link\">$book_name $chapter</a></b></font> <a href=\"?keyword=$n_ref$p_display_var\"><font size=\"1\" face=\"Verdana\">&gt;&gt; </font></a>";
  }
if($st_key)
  {
  $max="<center><font face=\"Verdana\" size=\"1\">$begin1 - $end of $max_rows verses containing <b>Strong's $kw_st</b>$section_searched.</font></center>";
  }
if(($keyword) and ($max_rows==0))
  {
  $keyword=str_replace('%22', '"', $keyword);
  if($book_name){$keyword="$book_name $reference_key";}
  if(!$keyword){$keyword=$original_keyword;}
  $max="<span name=wi0 id=wi0><font face=\"Verdana\" size=\"1\">Sorry, no results for <b>$keyword</b> could be found$section_searched.</font></span>";
  }
$lastnext="<table width=100% border=0><tr><td colspan=2 nowrap>$max</td></tr><tr><td colspan=2 align=center>$select_page</td></tr><tr><td align=left nowrap><font size=2>$last_20</font></td><td align=right nowrap><font size=2>$next_20</font></td></tr><tr><td colspan=2>";
$nextlast="<tr><td align=left nowrap><font size=2>$last_20</font></td><td align=right nowrap><font size=2>$next_20</font></td></tr><tr><td colspan=2 align=center>$select_page</td>";
$html_template=str_replace($results_marker, "$lastnext$results</td>$nextlast</tr></table>", $html_template);

$html_template=str_replace('<!-- this section may not be removed',
 "<p align=center><font color=\"$page_medium\" size=\"1\" face=\"MS Sans Serif\">The URL for this page is: <a href=\"$this_url\">$this_url</a></font></p>\n<!-- this section may not be removed",
$html_template);

#echo "pages=$pages<br>
#this_page=$this_page<br>
#page_start=$page_start<br>
#page_end=$page_end<br>";

$pageend=getmicrotime();
$speed=$pageend-$pagestart;
$dbspeed=$dbqueryend-$dbquerystart;
$dbspeed0=$dbqueryend0-$dbquerystart0;
$predbspeed=$dbquerystart0-$pagestart;
$remaining_time=$pageend-$dbqueryend;
#$html_template=str_replace('{{SPEED}}', "<center><font size=2>
#  $predbspeed seconds before query<br>
#  mySQL (count total) took $dbspeed0 seconds<br>
#  mySQL (fetch verses) took $dbspeed seconds<br>
#  remaining time took $remaining_time seconds<br>
#  page processed in $speed seconds<br>
#</font></center>", $html_template); 

if($lexicon=='ipd'){$html_template=str_replace('value="ipd" name="lexicon"', 'value="ipd" checked name="lexicon"', $html_template);}
else{$html_template=str_replace('value="str" name="lexicon"', 'value="str" checked name="lexicon"', $html_template);}

#echo "$wc_source<br>\n";
echo $html_template;
?> 
Return current item: phpBible