<?php
require('lib_bible.php');

$file = file_get_contents($some_file_path);
//Find a Bible reference of the form:
//$BRef_pattern is a global supplied by lib_bible.php
$file = preg_replace_callback($BRef_pattern, $BRef_pattern, $file);

function BRef_cb($match) {
    $ref = new BibleReference($match[0]);
    if (! $ref->book) {
        echo "Uknown reference:";
        return $match[0];
    }
    return $ref->linkedRef();
}
?>

Or if you want to make sure you do not add links inside of an anchor tag, try:
<?
    $marker = $BRef_pattern[0]; //Find the Regexp marker character
    //Get ending marker and modifiers
    $end = substr($BRef_pattern,strpos($BRef_pattern,$marker,1));
    //Get just the pattern without markers
    $pat = substr($BRef_pattern,1,strpos($BRef_pattern,$marker,1)-1);
    
    //Let $pat match a Bible reference or an anchor tag.  That way I won't get references in an anchor tag
    $pat = $marker . "(?:<a.*?(?:</a>|$)|" . $pat . ")" . $end;
    
    $text = preg_match($pat, BRef_cb, $text, $match);

    if (strpos($match[0], "<a") === FALSE) {
	$ref = new BibleReference($match[0]);
	if (! $ref->book) {
		echo "Uknown reference:";
	}
	echo $ref->linkedRef();
    }
?>