/**
 * Note: Try to avoid using this function. Use api_preg_match() with Perl-compatible regular expression syntax.
 *
 * Executes a regular expression match, ignoring case, with extended multibyte support.
 * By default this function uses the platform character set.
 * @param string $pattern            The regular expression pattern.
 * @param string $string            The searched string.
 * @param array $regs (optional)    If specified, by this passed by reference parameter an array containing found match and its substrings is returned.
 * @return mixed                    1 if match is found, FALSE if not. If $regs has been specified, byte-length of the found match is returned, or FALSE if no match has been found.
 * This function is aimed at replacing the functions eregi() and mb_eregi() for human-language strings.
 * @link http://php.net/manual/en/function.eregi
 * @link http://php.net/manual/en/function.mb-eregi
 */
function api_eregi($pattern, $string, &$regs = null)
{
    $count = func_num_args();
    $encoding = _api_mb_regex_encoding();
    if (_api_mb_supports($encoding)) {
        if ($count < 3) {
            return @mb_eregi($pattern, $string);
        }
        return @mb_eregi($pattern, $string, $regs);
    }
    if (MBSTRING_INSTALLED && api_is_encoding_supported($encoding)) {
        global $_api_encoding;
        $_api_encoding = $encoding;
        _api_mb_regex_encoding('UTF-8');
        if ($count < 3) {
            $result = @mb_eregi(api_utf8_encode($pattern, $encoding), api_utf8_encode($string, $encoding));
        } else {
            $result = @mb_eregi(api_utf8_encode($pattern, $encoding), api_utf8_encode($string, $encoding), $regs);
            $regs = _api_array_utf8_decode($regs);
        }
        _api_mb_regex_encoding($encoding);
        return $result;
    }
    if ($count < 3) {
        return eregi($pattern, $string);
    }
    return eregi($pattern, $string, $regs);
}
/**
 * Note: Try to avoid using this function. Use api_preg_split() with Perl-compatible regular expression syntax.
 *
 * Splits a multibyte string using regular expression pattern and returns the result as an array.
 * By default this function uses the platform character set.
 * @param string $pattern			The regular expression pattern.
 * @param string $string			The string being split.
 * @param int $limit (optional)		If this optional parameter $limit is specified, the string will be split in $limit elements as maximum.
 * @return array					The result as an array.
 * This function is aimed at replacing the functions split() and mb_split() for human-language strings.
 * @link http://php.net/manual/en/function.split
 * @link http://php.net/manual/en/function.mb-split
 */
function api_split($pattern, $string, $limit = null)
{
    $encoding = _api_mb_regex_encoding();
    if (_api_mb_supports($encoding)) {
        if (is_null($limit)) {
            return @mb_split($pattern, $string);
        }
        return @mb_split($pattern, $string, $limit);
    }
    if (MBSTRING_INSTALLED && api_is_encoding_supported($encoding)) {
        global $_api_encoding;
        $_api_encoding = $encoding;
        _api_mb_regex_encoding('UTF-8');
        if (is_null($limit)) {
            $result = @mb_split(api_utf8_encode($pattern, $encoding), api_utf8_encode($string, $encoding));
        } else {
            $result = @mb_split(api_utf8_encode($pattern, $encoding), api_utf8_encode($string, $encoding), $limit);
        }
        $result = _api_array_utf8_decode($result);
        _api_mb_regex_encoding($encoding);
        return $result;
    }
    if (is_null($limit)) {
        return split($pattern, $string);
    }
    return split($pattern, $string, $limit);
}