本文整理汇总了PHP中mb_split函数的典型用法代码示例。如果您正苦于以下问题:PHP mb_split函数的具体用法?PHP mb_split怎么用?PHP mb_split使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mb_split函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filter
/**
* Defined by Zend_Filter_Interface
*
* Returns $value translitered to ASCII
*
* @param string $value
* @return string
*/
public function filter($value)
{
//translitere specific chars
$value = $this->_transliterateCzech($value);
$value = $this->_transliterateSlovak($value);
$value = $this->_transliterateRussian($value);
$value = $this->_transliterateGerman($value);
$value = $this->_transliterateFrench($value);
$value = $this->_transliterateHungarian($value);
$value = $this->_transliteratePolish($value);
$value = $this->_transliterateDanish($value);
$value = $this->_transliterateCroatian($value);
//split string to single characters
$characters = mb_split("~(.)~", $value);
$return = '';
foreach ($characters as $character) {
/* maybe should contain also //IGNORE */
$converted = iconv("utf-8", "ASCII//TRANSLIT", $character);
//if character was converted, strip out wrong marks
if ($character !== $converted) {
$return .= preg_replace('~["\'^]+~', '', $converted);
} else {
$return .= $converted;
}
}
return $return;
}
示例2: unmarkedText
/**
* Inject span tags for each line to indicate direction.
*
* @param string $text Single line's worth of text.
* @return string
*/
protected function unmarkedText($text)
{
$newText = "";
if ($this->breaksEnabled) {
$parts = mb_split('[ ]*\\n', $text);
} else {
$parts = mb_split('(?:[ ][ ]+|[ ]*\\\\)\\n', $text);
}
foreach ($parts as $index => &$part) {
if ($index > 0) {
$newText .= "<br />\n";
}
// Remove trailing spaces.
$part = mb_ereg_replace('/[ ]*\\n/', "\n", $part);
// Determine directon
$ltr = $this->getLtrStrLen($part);
$rtl = $this->getRtlStrLen($part);
$dir = null;
if ($this->isLtr() && $rtl > 0 && $rtl > $ltr) {
$dir = "rtl";
} else {
if ($this->isRtl() && $ltr > 0 && $ltr > $rtl) {
$dir = "ltr";
}
}
if (!is_null($dir)) {
$newText .= "<div dir=\"{$dir}\">{$part}</div>";
} else {
$newText .= $part;
}
}
return $newText;
}
示例3: CheckThrottle
function CheckThrottle()
{
global $opt, $tpl;
$ip_string = $_SERVER['REMOTE_ADDR'];
$ip_blocks = mb_split('\\.', $ip_string);
$ip_numeric = $ip_blocks[3] + $ip_blocks[2] * 256 + $ip_blocks[1] * 65536 + $ip_blocks[0] * 16777216;
sql('CREATE TABLE IF NOT EXISTS &tmpdb.`sys_accesslog`
(`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `ip` INT UNSIGNED NOT NULL,
`access_time` TIMESTAMP NOT NULL, INDEX (`access_time`), INDEX (`ip`)) ENGINE = MEMORY');
$rsStaus = sql("SHOW STATUS LIKE 'Threads_connected'");
$rStatus = sql_fetch_array($rsStaus);
sql_free_result($rsStaus);
if ($rStatus) {
if ($rStatus[1] > $opt['db']['throttle_connection_count']) {
$access_count = sql_value("SELECT COUNT(*) FROM &tmpdb.`sys_accesslog` WHERE ip ='&1'", 0, $ip_numeric);
if ($access_count > $opt['db']['throttle_access_count']) {
$tpl->error(ERROR_THROOTLE);
}
}
}
// remove old entries every 100st call
if (mt_rand(0, 100) == 50) {
sql("DELETE FROM &tmpdb.`sys_accesslog` WHERE `access_time`<CURRENT_TIMESTAMP()-'&2'", $ip_numeric, $opt['db']['throttle_access_time']);
}
sql("INSERT INTO &tmpdb.`sys_accesslog` (`ip`, `access_time`) VALUES ('&1', CURRENT_TIMESTAMP())", $ip_numeric);
}
示例4: get_alphabet
protected static function get_alphabet()
{
if (!empty(self::$alphabet)) {
return;
}
/* translators: List the aphabet of your language in the order that your language prefers. list as groups of identical meanings but different characters together, e.g. in English we group A with a because they are both the same letter but different character-code. Each character group should be followed by a comma separating it from the next group. Any amount of characters per group are acceptible, and there is no requirement for all the groups to contain the same amount of characters as all the others. Be careful with the character you place first in each group as that will be used as the identifier for the group which gets displayed on the page, e.g. in English a group definition of "Aa" will indicate that we display all the posts in the group, i.e. whose titles begin with either "A" or "a", listed under a heading of "A" (the first character in the definition). */
$alphabet = apply_filters('a-z-listing-alphabet', __('AÁÀÄÂaáàäâ,Bb,Cc,Dd,EÉÈËÊeéèëê,Ff,Gg,Hh,IÍÌÏÎiíìïî,Jj,Kk,Ll,Mm,Nn,OÓÒÖÔoóòöô,Pp,Qq,Rr,Ssß,Tt,UÚÙÜÛuúùüû,Vv,Ww,Xx,Yy,Zz'));
/* translators: This should be a single character to denote "all entries that didn't fit under one of the alphabet character groups defined". This is used in English to categorise posts whose title begins with a numeric (0 through to 9), or some other character that is not a standard English alphabet letter. */
$others = apply_filters('a-z-listing-non-alpha-char', __('#', 'a-z-listing'));
$alphabet_groups = mb_split(',', $alphabet);
$letters = array_reduce($alphabet_groups, function ($return, $group) {
$group = A_Z_Listing::mb_string_to_array($group);
$group_index_character = $group[0];
$group = array_reduce($group, function ($group, $character) use($group_index_character) {
$group[$character] = $group_index_character;
return $group;
});
if (!is_array($return)) {
return $group;
}
return array_merge($return, $group);
});
self::$alphabet = $letters;
self::$unknown_letters = $others;
}
示例5: detect
public static function detect($string)
{
$string = mb_strtolower($string, "UTF-8");
// make it lowercase
$matchWords = mb_split(" ", $string);
array_walk($matchWords, 'trim');
foreach ($matchWords as $key => $item) {
if ($item == '' || strlen($item) <= 6) {
unset($matchWords[$key]);
}
}
$wordCountArr = array();
if (is_array($matchWords)) {
foreach ($matchWords as $key => $val) {
$val = mb_strtolower($val, "UTF-8");
if (isset($wordCountArr[$val])) {
$wordCountArr[$val]++;
} else {
$wordCountArr[$val] = 1;
}
}
}
arsort($wordCountArr);
$wordCountArr = array_slice($wordCountArr, 0, 10);
$returnArr = array();
foreach ($wordCountArr as $word => $count) {
if ($count > 3) {
$returnArr[] = $word;
}
}
return $returnArr;
}
示例6: split
public function split($string = '', $pattern = '', $limit = -1)
{
if (!is_string($string) || !is_string($pattern)) {
return Error::set('Error', 'stringParameter', '1.(string) & 2.(pattern)');
}
return mb_split($pattern, $string, $limit);
}
示例7: __construct
/**
* accept the request or CLI parameters
* @param string $pty request data priority:
* J - json
* P - post
* G - get
*/
public function __construct($pty = 'JPG')
{
global $argc, $argv;
if (empty($argc)) {
// request parameters
$jsn = @json_decode(file_get_contents('php://input'), true);
// check for json body
if (is_array($jsn)) {
$this->jsn = $jsn;
// json request
} else {
$this->jsn = isset($_SERVER['CONTENT_TYPE']) && strpos($_SERVER['CONTENT_TYPE'], 'json') !== false ? array() : false;
// empty json body?
$jsn = array();
// no json data
}
$this->Merge(array('J' => $jsn, 'P' => $_POST, 'G' => $_GET), strtoupper($pty));
// save
} else {
// CLI arguments
for ($i = 1; $i < $argc; $i++) {
// loop the arguments
$arg = mb_split('=', $argv[$i]);
// split to key/value
$this->rqt[$arg[0]] = $arg[1];
// save
}
}
}
示例8: parse
/**
* Parse title of the question by
* tokenizing it
* Overrides parent's parse and users mb_split
* instead of preg_split to be UTF-8 Safe
* because title can be a UTF-8 string
*
* @return array tokens;
*/
public function parse()
{
if (empty($this->origString)) {
d('string was empty, returning empty array');
return array();
}
\mb_regex_encoding('UTF-8');
$aTokens = \mb_split('([\\s,;\\"\\?]+)', $this->origString);
$aTokens = \array_unique($aTokens);
$aStopwords = getStopwords();
\array_walk($aTokens, function (&$val) use($aStopwords) {
$val = \trim($val);
$val = strlen($val) > 1 && !in_array($val, $aStopwords) ? $val : false;
});
/**
* Remove empty values
*
*/
$aTokens = \array_filter($aTokens);
/**
* Call array_values to reindex from 0
* otherwise if filter removed some
* elements then Mongo will not
* treat this as normal array
*/
return \array_values($aTokens);
}
示例9: update_server
/**
* @param announcement Server announcement string. UTF-8 assumed.
* @param addr Remote server address.
*/
function update_server($announcement, $addr)
{
mb_regex_encoding('UTF-8');
mb_internal_encoding('UTF-8');
// First we must determine if the announcement is valid.
$lines = mb_split("\r\n|\n|\r", $announcement);
$info = new ServerInfo();
while (list($line_number, $line) = each($lines)) {
// Separate the label from the value.
$colon = strpos($line, ":");
// It must exist near the beginning.
if ($colon === false || $colon >= 16) {
continue;
}
$label = substr($line, 0, $colon);
$value = substr($line, $colon + 1, strlen($line) - $colon - 1);
if (strlen($value) >= 128) {
continue;
}
// Ensure the label identifies a known property.
if (isset($info[$label])) {
// This will be included in the datafile.
$info[$label] = $value;
}
}
// Also include the remote address.
$info['at'] = $addr;
$info['time'] = time();
// Let's write this info into the datafile.
write_server($info);
}
示例10: do_url
function do_url()
{
$page = $this->getcurrentPage();
if ($page->isexist()) {
$html = convert_Page($page);
if (keys_exists(Vars::$get, 'word', 'type')) {
$list = mb_split('[\\s ]', Vars::$get['word']);
$smarty = $this->getSmarty();
$smarty->assign('word', $list);
$smarty->assign('type', Vars::$get['type']);
$smarty->assign('body', Search::getinstance()->mark($html, $list, Vars::$get['type']));
$html = $smarty->fetch('highlight.tpl.htm');
}
$ret['body'] = $html;
$ret['title'] = $page->getpagename();
$ret['pagename'] = $page->getpagename();
$ret['lastmodified'] = $page->gettimestamp();
} else {
$smarty = $this->getSmarty();
$smarty->assign('pagename', $page->getpagename());
$ret['body'] = $smarty->fetch('notexist.tpl.htm');
$ret['title'] = $page->getpagename() . ' は存在しません';
$ret['pagename'] = $page->getpagename();
}
return $ret;
}
示例11: load
function load($lang)
{
$col = $this->languages[$lang];
if (!$col) {
$col = 1;
}
$this->messages = array();
$path = CONF_DIR . 'messages/common.csv';
$fin = fopen($path, 'r');
while ($line = fgets($fin)) {
$line = rtrim($line);
if ($line[0] == "#") {
continue;
}
$cells = mb_split(';', $line);
if (count($cells) <= 1) {
continue;
}
$key = trim($cells[0]);
$value = $cells[$col];
if (!$value) {
continue;
}
$this->messages[$key] = $value;
}
fclose($fin);
}
示例12: wordwrapFilter
public function wordwrapFilter($value, $length = 60, $separator = "\n", $preserve = false)
{
$lines = array();
$value = str_replace("<p>", "", $value);
$value = str_replace("</p>", "\n\n", $value);
$value = preg_replace("/<br\\W*?\\/>/", "\n", $value);
if (substr($value, -2) == "\n\n") {
$value = substr($value, 0, -2);
}
$previous = mb_regex_encoding();
mb_regex_encoding(craft()->templates->getTwig()->getCharset());
$pieces = mb_split($separator, $value);
mb_regex_encoding($previous);
foreach ($pieces as $piece) {
while (!$preserve && mb_strlen($piece, craft()->templates->getTwig()->getCharset()) > $length) {
$count = count($lines);
$lines[] = mb_substr($piece, 0, $length, craft()->templates->getTwig()->getCharset());
$lastSpacePosition = strrpos($lines[$count], ' ', 0);
$finalCharacters = trim(substr($lines[$count], $lastSpacePosition, 60));
$lines[$count] = substr($lines[$count], 0, $lastSpacePosition);
$piece = $finalCharacters . $piece;
$piece = mb_substr($piece, $length, 2048, craft()->templates->getTwig()->getCharset());
}
$lines[] = $piece;
}
return implode($separator, $lines);
}
示例13: getLastGames
public static function getLastGames($count = 5)
{
$var = Yii::app()->redis->getClient()->get("lastGames");
if (!$var) {
return [];
}
$varArr = mb_split(":", $var);
$out = [];
foreach ($varArr as $item) {
$t = mb_split("\\|", $item);
$tmp = ["time" => $t[0], "gameId" => $t[1], "gameLink" => Yii::app()->createUrl("/stats/" . Yii::app()->params['gameTypes'][$t[2]]["url"] . "/view", ["id" => $t[1]]), "type" => $t[2], "typeLink" => Yii::app()->createUrl("/stats/" . Yii::app()->params['gameTypes'][$t[2]]["url"] . "/list"), "typeName" => Yii::app()->params['gameTypes'][$t[2]]["name"]];
if (Yii::app()->params['gameTypes'][$t[2]]["isTeams"]) {
$tmp['winner'] = Yii::app()->params['gameTypes'][$t[2]]["teams"][$t[3]] . " команда выиграла ";
} else {
$tmp['winner'] = Users::model()->getUsernameWithAvatarAndLink($t[3], 15) . " выиграл";
}
$out[] = $tmp;
}
$out = array_reverse($out);
$out1 = [];
$i = 1;
foreach ($out as $item) {
if ($i <= $count) {
$out1[] = $item;
} else {
break;
}
$i++;
}
return $out1;
}
示例14: wordsearch
protected function wordsearch()
{
if (!isset(Vars::$get['andor']) || !isset(Vars::$get['type'])) {
throw new CommandException('パラメータが足りません。', $this);
}
$word = array();
foreach (mb_split('[\\s ]+', Vars::$get['keyword']) as $w) {
if ($w != '') {
$word[] = $w;
}
}
if ($word == array()) {
return $this->showform();
}
$search = Search::getinstance();
$andsearch = Vars::$get['andor'] == 'and';
switch (Vars::$get['type']) {
case 'fuzzy':
$list = $search->fuzzysearch($word, $andsearch);
break;
case 'ereg':
$list = $search->eregsearch($word, $andsearch);
break;
default:
$list = $search->normalsearch($word, $andsearch);
break;
}
$smarty = $this->getSmarty();
$smarty->assign('word', join(' ', $word));
$smarty->assign('type', Vars::$get['type']);
$smarty->assign('list', $list);
$ret['title'] = '検索結果';
$ret['body'] = $smarty->fetch('wordsearchresult.tpl.htm');
return $ret;
}
示例15: __construct
/**
* @param string $string The string to parse
* @param ClassObject $extend optional, set if this ClassObject should extend another one
*/
public function __construct($string, ClassObject $extend = null)
{
if ($extend !== null) {
$this->attributes = $extend->getAttributes();
$this->methods = $extend->getMethods();
}
$pattern = '/' . self::PATTERN . '/i';
preg_match($pattern, $string, $matches);
$this->name = $matches[self::PATTERN_NAME_GROUP];
if (count($matches) > 2) {
$blocks = preg_split('/\\|/', $matches[2]);
// Attributes block
if (count($blocks) > 1) {
foreach (mb_split(';', $blocks[1]) as $attribute) {
if (!empty($attribute)) {
$this->attributes[] = new Variable($attribute);
}
}
}
// Methods block
if (count($blocks) > 2) {
foreach (mb_split(';', $blocks[2]) as $method) {
try {
$this->methods[] = new Method($method);
} catch (\InvalidArgumentException $e) {
}
}
}
}
}