规范化搜索关键词

@param string[]|string $str The dirty keywords
@param array $ignore Ignore words to strip out
@param bool $processCharMap Whether to remove punctuation and diacritics (default is true)
@return string The cleansed keywords.
164700
public static function normalizeKeywords($str, array $ignore = [], bool $processCharMap = true): string
    {
        // Flatten
        if (is_array($str)) {
            $str = StringHelper::toString($str, ' ');
        }

        // Get rid of tags
        $str = strip_tags($str);

        // Convert non-breaking spaces entities to regular ones
        $str = str_replace(['&nbsp;', '&#160;', '&#xa0;'], ' ', $str);

        // Get rid of entities
        $str = preg_replace('/&#?[a-z0-9]{2,8};/i', '', $str);

        // Normalize to lowercase
        $str = StringHelper::toLowerCase($str);

        if ($processCharMap) {
            // Remove punctuation and diacritics
            $str = strtr($str, self::_getCharMap());
        }

        // Remove ignore-words?
        if (is_array($ignore) && !empty($ignore)) {
            foreach ($ignore as $word) {
                $word = preg_quote(static::normalizeKeywords($word), '/');
                $str = preg_replace("/\b{$word}\b/u", '', $str);
            }
        }

        // Strip out new lines and superfluous spaces
        $str = preg_replace('/[\n\r]+/u', ' ', $str);
        $str = preg_replace('/\s{2,}/u', ' ', $str);

        // Trim white space
        $str = trim($str);

        return $str;
    }
847820
private function checkSignature($str='')
    {
        $signature = isset($_GET["signature"])?$_GET["signature"]:'';
        $signature = isset($_GET["msg_signature"])?$_GET["msg_signature"]:$signature; //如果存在加密验证则用加密验证段
        $timestamp = isset($_GET["timestamp"])?$_GET["timestamp"]:'';
        $nonce = isset($_GET["nonce"])?$_GET["nonce"]:'';

        $token = $this->token;
        $tmpArr = array($token, $timestamp, $nonce,$str);
        sort($tmpArr, SORT_STRING);
        $tmpStr = implode( $tmpArr );
        $tmpStr = sha1( $tmpStr );

        if( $tmpStr == $signature ){
            return true;
        }else{
            return false;
        }
    }
1265525
static public function toDashed($str, $convertToAscii = true) {
        if ($convertToAscii) {
            $str = self::utf8ToAscii($str);
        }

        $str = self::acronymsToLowercase($str);
        $str = preg_replace_callback(
            '/([A-Z])/',
            function ($str) {
                return "-" . strtolower($str[1]);
            },
            $str
        );
        $str = preg_replace('/[^a-z0-9]/', '-', $str);
        $str = preg_replace('/\-{2,}/', '-', $str);
        return trim($str, "\n\t -");
    }
186785
public function clean_string($str)
    {
        if ($this->is_ascii($str) === FALSE) {
            if (MB_ENABLED) {
                $str = mb_convert_encoding($str, 'UTF-8', 'UTF-8');
            } elseif (ICONV_ENABLED) {
                $str = @iconv('UTF-8', 'UTF-8//IGNORE', $str);
            }
        }

        return $str;
    }
441326
public static function removeEmoji(string $str): string
    {
        $patterns = [
            '/[\x{1F600}-\x{1F64F}]/u', // Emoticons
            '/[\x{1F300}-\x{1F5FF}]/u', // Miscellaneous symbols and pictographs
            '/[\x{1F680}-\x{1F6FF}]/u', // Transport and map symbols
            '/[\x{2600}-\x{26FF}]/u',   // Miscellaneous symbols
            '/[\x{2700}-\x{27BF}]/u',   // Dingbats
        ];

        foreach ($patterns as $pattern) {
            $str = preg_replace(
                $pattern,
                ' ',
                $str
            );
        }

        return static::removeMultipleSpaces($str);
    }
57475
private function sanitizeEscapedText($str)
    {
        $str = str_replace('&apos;', '&#39;', $str); // PHP's html_entity_decode doesn't seem to support that!

        /* <?php ?> blocks can't reliably work in attributes (due to escaping impossible in XML)
           so they have to be converted into special TALES expression
        */
        $types = version_compare(PHP_VERSION, '5.4.0') < 0 ? (ini_get('short_open_tag') ? 'php|=|' : 'php') : 'php|=';
        $str = preg_replace_callback("/<\?($types)(.*?)\?>/", array('self', 'convertPHPBlockToTALES'), $str);

        // corrects all non-entities and neutralizes potentially problematic CDATA end marker
        $str = strtr(preg_replace('/&(?!(?:#x?[a-f0-9]+|[a-z][a-z0-9]*);)/i', '&amp;', $str), array('<'=>'&lt;', ']]>'=>']]&gt;'));

        return $str;
    }
696250
public static function create($str, $camelize = true)
    {
        // remove special chars (accents, etc.)
        $str = trim(self::normalize($str));
        $str = ltrim($str, '#_ ');

        // handle some punctuation and convertable chars
        $find = ["'", "?", "#", "/", "\"", "\\", "&amp;", "&", "%", "@"];
        $repl = ['', '', '', '', '', '', ' And ', ' And ', ' Percent ', ' At '];
        $str = str_replace($find, $repl, $str);

        // replace everything else and split up the words
        $str = preg_replace('/[^a-zA-Z0-9_]/', ':', $str);
        if ($camelize) {
            $str = strtolower(preg_replace('/([A-Z])/', ':$1', $str));
            $str = str_replace(' ', '', ucwords(str_replace(':', ' ', $str)));
        } else {
            $str = str_replace(' ', '', str_replace(':', ' ', $str));
        }

        $str = ltrim($str, '_');
        $hashtag = '';
        $foundLetter = false;
        $len = strlen($str);
        if ($len > 139) {
            return null;
        }

        for ($i = 0; $i < $len; $i++) {
            $char = $str[$i];
            $hashtag .= $char;

            if (!$foundLetter && !is_numeric($char)) {
                $foundLetter = true;
            }
        }

        if (!$foundLetter) {
            return null;
        }

        return empty($hashtag) ? null : $hashtag;
    }
161508
public static function replaceSpecialChars($str)
    {
        return preg_replace(array_keys(self::$specialCharsArray), array_values(self::$specialCharsArray), $str);
    }
1213606
public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars)
    {
        $strlen = strlen($string);
        $ignoredChars = '';
        for ($i = 0; $i < $strlen; ++$i) {
            if ($string[$i] > "\x07F") {
                // Invalid char
                $currentMap[$i + $startOffset] = $string[$i];
            }
        }

        return $strlen;
    }
44545
function (str) {
            return _(str).chain()
                .unescapeHTML()
                .stripTags()
                .clean()
                .value()
                .replace( matchJunk, '' )
                .toLowerCase();
        }
1230081
public static function getClean($str)
    {
        if (is_object($str) && get_class($str) == 'Xiphe\HTML\core\Tag') {
            $Tag = $str;
            $str = $Tag->content;
        }
        switch (Config::get('cleanMode')) {
        case 'strong':
            $str = self::getStrong($str);
            break;
        case 'basic':
            $str = self::getBasic($str);
            break;
        default:
            return $str;
        }
        if (isset($Tag)) {
            $Tag->content = $str;
        }

        return $str;
    }
573970
public static function shyphenate($str)
    {
        $res = preg_match_all('/([a-z0-9]{19,})/i', $str, $matches);

        if ($res) {
            foreach ($matches[1] as $key => $match) {
                $str = str_replace($match, wordwrap($match, 10, '&shy;', true), $str);
            }
        }

        return $str;
    }
1360104
public static String cleanString(String pStr) {
        if (pStr == null || pStr.equals("")) {
            return pStr;
        }
        StringBuffer buff = new StringBuffer();
        for (int i = 0; i < pStr.length(); i++) {
            char aChar = pStr.charAt(i);
            if (Character.isLetterOrDigit(aChar)) {
                buff.append(aChar);
            }
        }
        return buff.toString();
    }
1255256
public static function removeInvisibleCharacters($str, $url_encoded = true)
    {
        $non_display_ables = array();

        // every control character except newline (dec 10)
        // carriage return (dec 13), and horizontal tab (dec 09)

        if ($url_encoded) {
            $non_display_ables[] = '/%0[0-8bcef]/';  // url encoded 00-08, 11, 12, 14, 15
            $non_display_ables[] = '/%1[0-9a-f]/';   // url encoded 16-31
        }

        $non_display_ables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S';   // 00-08, 11, 12, 14-31, 127

        do {
            $str = preg_replace($non_display_ables, '', $str, -1, $count);
        } while ($count);

        return $str;
    }
766538
function _remove_invisible_characters($str)
	{
		static $non_displayables;

		if ( ! isset($non_displayables))
		{
			// every control character except newline (dec 10), carriage return (dec 13), and horizontal tab (dec 09),
			$non_displayables = array(
										'/%0[0-8bcef]/',			// url encoded 00-08, 11, 12, 14, 15
										'/%1[0-9a-f]/',				// url encoded 16-31
										'/[\x00-\x08]/',			// 00-08
										'/\x0b/', '/\x0c/',			// 11, 12
										'/[\x0e-\x1f]/'				// 14-31
									);
		}

		do
		{
			$cleaned = $str;
			$str = preg_replace($non_displayables, '', $str);
		}
		while ($cleaned != $str);

		return $str;
	}
649525
public static function removeUnsafeChars($str) {
		static $blacklist = '/[!\"?():\']/';
		static $whitelist = '/[^a-zA-Z0-9-_.]/';
		$validStr = preg_replace(array($blacklist, $whitelist), array('', '-'), $str);
		return $validStr;
	}
1073449
public function toString($ignoreEmpty = false, $numPrefix = null, $separator = null)
    {
        if (empty($separator)) {
            $separator = '&';
        }

        return http_build_query(
            $this->toArray($ignoreEmpty),
            $numPrefix,
            $separator
        );
    }