Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

regular expressiong to indentify bible references in a sentence

<?php
$scriptureUtils = new ScriptureUtils();
echo $scriptureUtils->addLinks($text);

class ScriptureUtils {

    private $booksAbbreviated = array(
        "Gen", "Exo", "Lev", "Num", "Deu", "Jos", "Jud", "Rut", "1 Sam", "2 Sam", "1 Kin", 
        "2 Kin", "1 Chr", "2 Chr", "Ezr", "Neh", "Est", "Job", "Psa", "Pro", "Ecc", "Son", 
        "Isa", "Jer", "Lam", "Eze", "Dan", "Hos", "Joe", "Amo", "Oba", "Jon", "Mic", 
        "Nah", "Hab", "Zep", "Hag", "Zec", "Mal", "Mat", "Mar", "Luk", "Joh", "Act", 
        "Rom", "1 Cor", "2 Cor", "Gal", "Eph", "Phi", "Col", "1 The", "2 The", "1 Tim", 
        "2 Tim", "Tit", "Phi", "Heb", "Jam", "1 Pet", "2 Pet", "1 Joh", "2 Joh", "3 Joh", 
        "Jud", "Rev"
    );

    private $booksFullnames = 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", "Psalms", "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"
    );

    private $addLinkPattern;

    public function __construct() {
        $this->defineLinkPattern();
    }

    public function addLinks($text) {
        $returnString = preg_replace_callback(
            $this->addLinkPattern,
            array($this, "addLinkCallback"),
            $text
        );
        return $returnString;
    }

    private function addLinkCallback($matches) {
        $returnString = "";
        foreach($matches as $match) {
            $returnString .= "<a href="bible.php?passage=$match">$match</a>";
        }
        return $returnString;
    }

    private function defineLinkPattern() {
        // It is important that the full names appear before the abbreviated ones.
        $bookList = implode("|", array_merge($this->booksFullnames, $this->booksAbbreviated));
        $this->addLinkPattern = "/(?:$bookList)(?:s+d+)?(?::d+(?:–d+)?(?:,s*d+(?:–d+)?)*)?/";
    }

}
Comment

PREVIOUS NEXT
Code Example
Javascript :: props with ternary in react 
Javascript :: catch the last item in a array js 
Javascript :: toast duplicate angular 
Javascript :: var quotes 
Javascript :: jquery: return true or false if the element is present in the DOM or not 
Javascript :: Datatable search input with no label - just the placeholder 
Javascript :: geocoding react 
Javascript :: how to make a <li when clicked on a button js 
Javascript :: const { message } 
Javascript :: functiong of array sort 
Javascript :: useContext from localhost 
Javascript :: Deputy json file 
Javascript :: jquery element by name 
Javascript :: trie node pseudocode 
Javascript :: how to disable gravity for an object in matter.js 
Javascript :: count number of vowels in a string javascript 
Javascript :: mysql timestamp to time/days ago function 
Javascript :: js unslick 
Javascript :: push code from vscode using CL 
Javascript :: json.parse() javascript 
Javascript :: hover inline css 
Javascript :: release mouse key javascript 
Javascript :: Vue Apexchart LineChart 
Javascript :: handle stream javascript 
Javascript :: javascript change color of button onclick 
Javascript :: How to handle protected routes in React plus redirect user to original URL being visited 
Javascript :: edit mongodb array if checkbox is checked 
Javascript :: JS mixin implementation 
Javascript :: bind() method #1 
Javascript :: random color javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =