本文整理汇总了PHP中FeatherBB\Core\Utils::ucp_preg_replace方法的典型用法代码示例。如果您正苦于以下问题:PHP Utils::ucp_preg_replace方法的具体用法?PHP Utils::ucp_preg_replace怎么用?PHP Utils::ucp_preg_replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FeatherBB\Core\Utils
的用法示例。
在下文中一共展示了Utils::ucp_preg_replace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: split_words
public function split_words($text, $idx)
{
// Remove BBCode
$text = preg_replace('%\\[/?(b|u|s|ins|del|em|i|h|colou?r|quote|code|img|url|email|list|topic|post|forum|user)(?:\\=[^\\]]*)?\\]%', ' ', $text);
// Remove any apostrophes or dashes which aren't part of words
$text = substr(Utils::ucp_preg_replace('%((?<=[^\\p{L}\\p{N}])[\'\\-]|[\'\\-](?=[^\\p{L}\\p{N}]))%u', '', ' ' . $text . ' '), 1, -1);
// Remove punctuation and symbols (actually anything that isn't a letter or number), allow apostrophes and dashes (and % * if we aren't indexing)
$text = Utils::ucp_preg_replace('%(?![\'\\-' . ($idx ? '' : '\\%\\*') . '])[^\\p{L}\\p{N}]+%u', ' ', $text);
// Replace multiple whitespace or dashes
$text = preg_replace('%(\\s){2,}%u', '\\1', $text);
// Fill an array with all the words
$words = array_unique(explode(' ', $text));
// Remove any words that should not be indexed
foreach ($words as $key => $value) {
// If the word shouldn't be indexed, remove it
if (!$this->validate_search_word($value, $idx)) {
unset($words[$key]);
}
}
return $words;
}
示例2: check_username
public function check_username($username, $errors, $exclude_id = null)
{
// Include UTF-8 function
require_once ForumEnv::get('FEATHER_ROOT') . 'featherbb/Helpers/utf8/strcasecmp.php';
translate('register');
translate('prof_reg');
// Convert multiple whitespace characters into one (to prevent people from registering with indistinguishable usernames)
$username = preg_replace('%\\s+%s', ' ', $username);
// Validate username
if (Utils::strlen($username) < 2) {
$errors[] = __('Username too short');
} elseif (Utils::strlen($username) > 25) {
// This usually doesn't happen since the form element only accepts 25 characters
$errors[] = __('Username too long');
} elseif (!strcasecmp($username, 'Guest') || !utf8_strcasecmp($username, __('Guest'))) {
$errors[] = __('Username guest');
} elseif (filter_var($username, FILTER_VALIDATE_IP)) {
$errors[] = __('Username IP');
} elseif ((strpos($username, '[') !== false || strpos($username, ']') !== false) && strpos($username, '\'') !== false && strpos($username, '"') !== false) {
$errors[] = __('Username reserved chars');
} elseif (preg_match('%(?:\\[/?(?:b|u|s|ins|del|em|i|h|colou?r|quote|code|img|url|email|list|\\*|topic|post|forum|user)\\]|\\[(?:img|url|quote|list)=)%i', $username)) {
$errors[] = __('Username BBCode');
}
// Check username for any censored words
if (ForumSettings::get('o_censoring') == '1' && Utils::censor($username) != $username) {
$errors[] = __('Username censor');
}
// Check that the username (or a too similar username) is not already registered
$query = !is_null($exclude_id) ? ' AND id!=' . $exclude_id : '';
$result = DB::for_table('online')->raw_query('SELECT username FROM ' . ForumSettings::get('db_prefix') . 'users WHERE (UPPER(username)=UPPER(:username1) OR UPPER(username)=UPPER(:username2)) AND id>1' . $query, array(':username1' => $username, ':username2' => Utils::ucp_preg_replace('%[^\\p{L}\\p{N}]%u', '', $username)))->find_one();
if ($result) {
$busy = $result['username'];
$errors[] = __('Username dupe 1') . ' ' . Utils::escape($busy) . '. ' . __('Username dupe 2');
}
// Check username for any banned usernames
foreach (Container::get('bans') as $cur_ban) {
if ($cur_ban['username'] != '' && utf8_strtolower($username) == utf8_strtolower($cur_ban['username'])) {
$errors[] = __('Banned username');
break;
}
}
return $errors;
}