public static function textMatch($haystack, $needle, $collation, $matchType = 'contains')
    {
        switch ($collation) {
            case 'i;ascii-casemap':
                // default strtolower takes locale into consideration
                // we don't want this.
                $haystack = str_replace(range('a', 'z'), range('A', 'Z'), $haystack);
                $needle = str_replace(range('a', 'z'), range('A', 'Z'), $needle);
                break;

            case 'i;octet':
                // Do nothing
                break;

            case 'i;unicode-casemap':
                $haystack = mb_strtoupper($haystack, 'UTF-8');
                $needle = mb_strtoupper($needle, 'UTF-8');
                break;

            default:
                throw new Exception\BadRequest('Collation type: '.$collation.' is not supported');
        }

        switch ($matchType) {
            case 'contains':
                return false !== strpos($haystack, $needle);
            case 'equals':
                return $haystack === $needle;
            case 'starts-with':
                return 0 === strpos($haystack, $needle);
            case 'ends-with':
                return strrpos($haystack, $needle) === strlen($haystack) - strlen($needle);
            default:
                throw new Exception\BadRequest('Match-type: '.$matchType.' is not supported');
        }
    }
public static function textMatch($haystack, $needle, $collation, $matchType = 'contains')
    {
        switch ($collation) {
            case 'i;ascii-casemap':
                // default strtolower takes locale into consideration
                // we don't want this.
                $haystack = str_replace(range('a', 'z'), range('A', 'Z'), $haystack);
                $needle = str_replace(range('a', 'z'), range('A', 'Z'), $needle);
                break;

            case 'i;octet':
                // Do nothing
                break;

            case 'i;unicode-casemap':
                $haystack = mb_strtoupper($haystack, 'UTF-8');
                $needle = mb_strtoupper($needle, 'UTF-8');
                break;

            default:
                throw new Exception\BadRequest('Collation type: '.$collation.' is not supported');
        }

        switch ($matchType) {
            case 'contains':
                return false !== strpos($haystack, $needle);
            case 'equals':
                return $haystack === $needle;
            case 'starts-with':
                return 0 === strpos($haystack, $needle);
            case 'ends-with':
                return strrpos($haystack, $needle) === strlen($haystack) - strlen($needle);
            default:
                throw new Exception\BadRequest('Match-type: '.$matchType.' is not supported');
        }
    }
public static function textMatch ( $ haystack , $ needle , $ collation , $ matchType = 'contains' ) { switch ( $ collation ) { case 'i;ascii-casemap' : // default strtolower takes locale into consideration // we don't want this. $ haystack = str_replace ( range ( 'a' , 'z' ) , range ( 'A' , 'Z' ) , $ haystack ) ; $ needle = str_replace ( range ( 'a' , 'z' ) , range ( 'A' , 'Z' ) , $ needle ) ; break ; case 'i;octet' : // Do nothing break ; case 'i;unicode-casemap' : $ haystack = mb_strtoupper ( $ haystack , 'UTF-8' ) ; $ needle = mb_strtoupper ( $ needle , 'UTF-8' ) ; break ; default : throw new Exception \ BadRequest ( 'Collation type: ' . $ collation . ' is not supported' ) ; } switch ( $ matchType ) { case 'contains' : return false !== strpos ( $ haystack , $ needle ) ; case 'equals' : return $ haystack === $ needle ; case 'starts-with' : return 0 === strpos ( $ haystack , $ needle ) ; case 'ends-with' : return strrpos ( $ haystack , $ needle ) === strlen ( $ haystack ) - strlen ( $ needle ) ; default : throw new Exception \ BadRequest ( 'Match-type: ' . $ matchType . ' is not supported' ) ; } }
Checks if a needle occurs in a haystack ;).

@param string $haystack
@param string $needle
@param string $collation
@param string $matchType

@return bool
Checks if a needle occurs in a haystack ; ) .