本文整理汇总了PHP中utf8_str_split函数的典型用法代码示例。如果您正苦于以下问题:PHP utf8_str_split函数的具体用法?PHP utf8_str_split怎么用?PHP utf8_str_split使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了utf8_str_split函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: decorateYear
/**
* Decorates the given year.
*
* @param $year
* @return string
*/
protected function decorateYear($year)
{
$year = utf8_str_split($year);
$modifier = '״' . array_pop($year);
array_push($year, $modifier);
return implode($year);
}
示例2: sum
/**
* Get the sum of the word numerical representation.
*
* @param $word
* @param bool $hebrewYear
* @return number
*/
public function sum($word, $hebrewYear = false)
{
$this->validateHebrewCharactersOnly($word);
$letters = utf8_str_split($word);
$letters[0] = $letters[0] == 'ה' && $hebrewYear ? 5000 : $letters[0];
return array_sum(array_map(function ($letter) {
return is_numeric($letter) ? $letter : self::numerology[$letter];
}, $letters));
}
示例3: CheckUpperLetters
function CheckUpperLetters($st)
{
$lv = "AĀBCČDEĒFGĢHIĪJKĶLĻMNŅOPRSŠTUŪVZŽ";
$arr1 = utf8_str_split($st);
$let = $arr1[0];
// 1 burts
$arr2 = utf8_str_split($lv);
// char of latvian upper letters
for ($i = 0; $i < strlen($lv) - 1; $i++) {
if ($let == $arr2[$i]) {
return TRUE;
}
}
return FALSE;
}
示例4: str_split
/**
* UTF-8 aware alternative to str_split
* Convert a string to an array
*
* @param string $str UTF-8 encoded string to process
* @param integer $split_len Number to characters to split string by
*
* @return array
*
* @see http://www.php.net/str_split
* @since 11.1
*/
public static function str_split($str, $split_len = 1)
{
jimport('phputf8.str_split');
return utf8_str_split($str, $split_len);
}
示例5: mail_encode
/**
* Encodes the given string for proper display in UTF-8.
*
* This version is using base64 encoded data. The downside of this
* is if the mail client does not understand this encoding the user
* is basically doomed with an unreadable subject.
*
* Please note that this version fully supports RFC 2045 section 6.8.
*/
function mail_encode($str)
{
// define start delimimter, end delimiter and spacer
$start = "=?UTF-8?B?";
$end = "?=";
$spacer = $end . ' ' . $start;
$split_length = 64;
$encoded_str = base64_encode($str);
// If encoded string meets the limits, we just return with the correct data.
if (strlen($encoded_str) <= $split_length) {
return $start . $encoded_str . $end;
}
// If there is only ASCII data, we just return what we want, correctly splitting the lines.
if (strlen($str) === utf8_strlen($str)) {
return $start . implode($spacer, str_split($encoded_str, $split_length)) . $end;
}
// UTF-8 data, compose encoded lines
$array = utf8_str_split($str);
$str = '';
while (sizeof($array)) {
$text = '';
while (sizeof($array) && intval((strlen($text . $array[0]) + 2) / 3) << 2 <= $split_length) {
$text .= array_shift($array);
}
$str .= $start . base64_encode($text) . $end . ' ';
}
return substr($str, 0, -1);
}
示例6: truncate_string
/**
* Truncates string while retaining special characters if going over the max length
* The default max length is 60 at the moment
* The maximum storage length is there to fit the string within the given length. The string may be further truncated due to html entities.
* For example: string given is 'a "quote"' (length: 9), would be a stored as 'a "quote"' (length: 19)
*
* @param string $string The text to truncate to the given length. String is specialchared.
* @param int $max_length Maximum length of string (multibyte character count as 1 char / Html entity count as 1 char)
* @param int $max_store_length Maximum character length of string (multibyte character count as 1 char / Html entity count as entity chars).
* @param bool $allow_reply Allow Re: in front of string
* NOTE: This parameter can cause undesired behavior (returning strings longer than $max_store_length) and is deprecated.
* @param string $append String to be appended
*/
function truncate_string($string, $max_length = 60, $max_store_length = 255, $allow_reply = false, $append = '')
{
$chars = array();
$strip_reply = false;
$stripped = false;
if ($allow_reply && strpos($string, 'Re: ') === 0) {
$strip_reply = true;
$string = substr($string, 4);
}
$_chars = utf8_str_split(htmlspecialchars_decode($string));
$chars = array_map('utf8_htmlspecialchars', $_chars);
// Now check the length ;)
if (sizeof($chars) > $max_length) {
// Cut off the last elements from the array
$string = implode('', array_slice($chars, 0, $max_length - utf8_strlen($append)));
$stripped = true;
}
// Due to specialchars, we may not be able to store the string...
if (utf8_strlen($string) > $max_store_length) {
// let's split again, we do not want half-baked strings where entities are split
$_chars = utf8_str_split(htmlspecialchars_decode($string));
$chars = array_map('utf8_htmlspecialchars', $_chars);
do {
array_pop($chars);
$string = implode('', $chars);
} while (!empty($chars) && utf8_strlen($string) > $max_store_length);
}
if ($strip_reply) {
$string = 'Re: ' . $string;
}
if ($append != '' && $stripped) {
$string = $string . $append;
}
return $string;
}
示例7: getQuestion
/**
* Generate the captcha question
*
* @return string The question string
*/
protected function getQuestion()
{
$int1 = rand(1, 9);
$int2 = rand(1, 9);
$question = $GLOBALS['TL_LANG']['SEC']['question' . rand(1, 3)];
$question = sprintf($question, $int1, $int2);
$this->Session->set('captcha_' . $this->strId, array('sum' => $int1 + $int2, 'key' => $this->strCaptchaKey, 'time' => time()));
$strEncoded = '';
$arrCharacters = utf8_str_split($question);
foreach ($arrCharacters as $strCharacter) {
$strEncoded .= sprintf('&#%s;', utf8_ord($strCharacter));
}
return $strEncoded;
}
示例8: mail_encode
/**
* Encodes the given string for proper display in UTF-8.
*
* This version is using base64 encoded data. The downside of this
* is if the mail client does not understand this encoding the user
* is basically doomed with an unreadable subject.
*
* Please note that this version fully supports RFC 2045 section 6.8.
*
* @param string $eol End of line we are using (optional to be backwards compatible)
*/
function mail_encode($str, $eol = "\r\n")
{
// define start delimimter, end delimiter and spacer
$start = "=?UTF-8?B?";
$end = "?=";
$delimiter = "{$eol} ";
// Maximum length is 75. $split_length *must* be a multiple of 4, but <= 75 - strlen($start . $delimiter . $end)!!!
$split_length = 60;
$encoded_str = base64_encode($str);
// If encoded string meets the limits, we just return with the correct data.
if (strlen($encoded_str) <= $split_length) {
return $start . $encoded_str . $end;
}
// If there is only ASCII data, we just return what we want, correctly splitting the lines.
if (strlen($str) === utf8_strlen($str)) {
return $start . implode($end . $delimiter . $start, str_split($encoded_str, $split_length)) . $end;
}
// UTF-8 data, compose encoded lines
$array = utf8_str_split($str);
$str = '';
while (sizeof($array)) {
$text = '';
while (sizeof($array) && intval((strlen($text . $array[0]) + 2) / 3) << 2 <= $split_length) {
$text .= array_shift($array);
}
$str .= $start . base64_encode($text) . $end . $delimiter;
}
return substr($str, 0, -strlen($delimiter));
}
示例9: str_split
/**
* UTF-8 aware alternative to str_split
* Convert a string to an array
*
* @param string $str UTF-8 encoded string to process
* @param integer $split_len Number to characters to split string by
*
* @return array
*
* @see http://www.php.net/str_split
* @since 2.0
*/
public static function str_split($str, $split_len = 1)
{
if (!function_exists('utf8_str_split')) {
require_once __DIR__ . '/phputf8/str_split.php';
}
return utf8_str_split($str, $split_len);
}
示例10: testSplitNewline
function testSplitNewline()
{
$str = "Iñtërn\nâtiônàl\nizætiøn\n";
$array = array('I', 'ñ', 't', 'ë', 'r', 'n', "\n", 'â', 't', 'i', 'ô', 'n', 'à', 'l', "\n", 'i', 'z', 'æ', 't', 'i', 'ø', 'n', "\n");
$this->assertEqual(utf8_str_split($str), $array);
}
示例11: str_split
/**
* UTF-8 aware alternative to str_split
* Convert a string to an array
*
* @param string $str UTF-8 encoded string to process
* @param integer $split_len Number to characters to split string by
*
* @return array
*
* @see http://www.php.net/str_split
* @since 1.0
*/
public static function str_split($str, $split_len = 1)
{
require_once __DIR__ . '/phputf8/str_split.php';
return utf8_str_split($str, $split_len);
}
示例12: str_split
/**
* UTF-8 aware alternative to str_split()
*
* Convert a string to an array.
*
* @param string $str UTF-8 encoded string to process
* @param integer $split_len Number to characters to split string by
*
* @return array
*
* @see http://www.php.net/str_split
* @since 1.3.0
*/
public static function str_split($str, $split_len = 1)
{
return utf8_str_split($str, $split_len);
}
示例13: encodeEmail
/**
* Encode all e-mail addresses within a string
*
* @param string $strString The string to encode
*
* @return string The encoded string
*/
public static function encodeEmail($strString)
{
$arrEmails = array();
preg_match_all('/\\w([-.+!#$%&\'*\\/=?^`{}|~\\w]*\\w)?@\\w([-.\\w]*\\w)?\\.\\w{2,63}/u', $strString, $arrEmails);
foreach ((array) $arrEmails[0] as $strEmail) {
$strEncoded = '';
$arrCharacters = utf8_str_split($strEmail);
foreach ($arrCharacters as $strCharacter) {
$strEncoded .= sprintf(rand(0, 1) ? '&#x%X;' : '&#%s;', utf8_ord($strCharacter));
}
$strString = str_replace($strEmail, $strEncoded, $strString);
}
return str_replace('mailto:', 'mailto:', $strString);
}