Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save xeoncross/9534124 to your computer and use it in GitHub Desktop.

Select an option

Save xeoncross/9534124 to your computer and use it in GitHub Desktop.

Revisions

  1. @oleosjo oleosjo revised this gist Mar 7, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion PHP Sort by Scripture (Bible)
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@
    return ($na < $nb) ? -1 : 1;
    }

    $position = key(preg_grep('/^'.$a.'(.*)\b/', $order));
    $position = key(preg_grep('/^'.$a.'(.*)\b/', $order));
    $position2 = key(preg_grep('/^'.$b.'(.*)\b/', $order));

    if ($position2!==false && $position!==false) {return ($position < $position2) ? -1 : 1;}
  2. @oleosjo oleosjo renamed this gist Mar 7, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @oleosjo oleosjo created this gist Mar 7, 2013.
    40 changes: 40 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    function scripturesort($a, $b) {
    if ($a == $b) {return 0;}
    $order=array("Genesis", "Exodus", "Leviticus", "Numbers", "Deuteronomy", "Joshua", "Judges", "Ruth", "1 Samuel", "2 Samuel", "1 Kings", "2 Kings", "1 Chronicles", "2 Chronicles", "Ezra", "Nehemiah", "Esther", "Job", "Psalm", "Proverbs", "Ecclesiastes", "Song of Solomon", "Isaiah", "Jeremiah", "Lamentations", "Ezekiel", "Daniel", "Hosea", "Joel", "Amos", "Obadiah", "Jonah", "Micah", "Nahum", "Habakkuk", "Zephaniah", "Haggai", "Zechariah", "Malachi", "Matthew", "Mark", "Luke", "John", "Acts", "Romans", "1 Corinthians", "2 Corinthians", "Galatians", "Ephesians", "Philippians", "Colossians", "1 Thessalonians", "2 Thessalonians", "1 Timothy", "2 Timothy", "Titus", "Philemon", "Hebrews", "James", "1 Peter", "2 Peter", "1 John", "2 John", "3 John", "Jude", "Revelation");

    $fa = $a;
    $fb = $b;

    preg_match('/^..(.+?)\b/', $a, $matches);
    $a = trim(substr($matches[0],0,4));

    preg_match('/^..(.+?)\b/', $b, $matches);
    $b = trim(substr($matches[0],0,4));

    similar_text($a, $b, $p);
    if($p > 75) {
    preg_match('/(.+?)([\d]+)/', $fa, $matches);
    $na = intval($matches[2]);
    preg_match('/(.+?)([\d]+)/', $fb, $matches);
    $nb = intval($matches[2]);
    if($na == $nb) {
    preg_match('/(.+?)([\d]+).*?:([\d]+)/', $fa, $matches);
    $n2a = intval($matches[3]);
    preg_match('/(.+?)([\d]+).*?:([\d]+)/', $fb, $matches);
    $n2b = intval($matches[3]);
    return ($n2a < $n2b) ? -1 : 1;
    } else
    return ($na < $nb) ? -1 : 1;
    }

    $position = key(preg_grep('/^'.$a.'(.*)\b/', $order));
    $position2 = key(preg_grep('/^'.$b.'(.*)\b/', $order));

    if ($position2!==false && $position!==false) {return ($position < $position2) ? -1 : 1;}
    if($position!==false) {return -1;}
    if($position2!==false) {return 1;}

    return ($a < $b) ? -1 : 1;
    }

    usort($scriptures, 'scripturesort');