src/Match.php
public function main($text, $pattern, $loc = 0){
        // Check for null inputs.
        if (!isset($text, $pattern)) {
            throw new \InvalidArgumentException("Null inputs.");
        }

        $loc = max(0, min($loc, mb_strlen($text)));
        if ($text == $pattern) {
            // Shortcut (potentially not guaranteed by the algorithm)
            return 0;
        } elseif ($text == '') {
            // Nothing to match.
            return -1;
        } elseif (mb_substr($text, $loc, mb_strlen($pattern)) == $pattern) {
            // Perfect match at the perfect spot!  (Includes case of null pattern)
            return $loc;
        } else {
            // Do a fuzzy compare.
            return  $this->bitap($text, $pattern, $loc);
        }
    }
public function main($text, $pattern, $loc = 0){
        // Check for null inputs.
        if (!isset($text, $pattern)) {
            throw new \InvalidArgumentException("Null inputs.");
        }

        $loc = max(0, min($loc, mb_strlen($text)));
        if ($text == $pattern) {
            // Shortcut (potentially not guaranteed by the algorithm)
            return 0;
        } elseif ($text == '') {
            // Nothing to match.
            return -1;
        } elseif (mb_substr($text, $loc, mb_strlen($pattern)) == $pattern) {
            // Perfect match at the perfect spot!  (Includes case of null pattern)
            return $loc;
        } else {
            // Do a fuzzy compare.
            return  $this->bitap($text, $pattern, $loc);
        }
    }
Locate the best instance of 'pattern' in 'text' near 'loc'.

@param string $text    The text to search.
@param string $pattern The pattern to search for.
@param int    $loc     The location to search around.

@throws \InvalidArgumentException If null inout.
@return int Best match index or -1.