本文整理汇总了PHP中Patchwork\Utf8::str_split方法的典型用法代码示例。如果您正苦于以下问题:PHP Utf8::str_split方法的具体用法?PHP Utf8::str_split怎么用?PHP Utf8::str_split使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Patchwork\Utf8
的用法示例。
在下文中一共展示了Utf8::str_split方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
/**
* @covers Patchwork\Utf8::str_split
*/
function testStr_split()
{
$this->assertSame(array('d', 'é', 'j', 'à'), u::str_split('déjà', 1));
$this->assertSame(array('dé', 'jà'), u::str_split('déjà', 2));
}
示例2: 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)
{
foreach (static::extractEmail($strString) 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);
}
示例3: api_str_split
/**
* Converts a string to an array.
* @param string $string The input string.
* @param int $split_length Maximum character-length of the chunk, one character by default.
* @param string $encoding (optional) The used internally by this function character encoding. If it is omitted, the platform character set will be used by default.
* @return array The result array of chunks with the spcified length.
* Notes:
* If the optional split_length parameter is specified, the returned array will be broken down into chunks
* with each being split_length in length, otherwise each chunk will be one character in length.
* FALSE is returned if split_length is less than 1.
* If the split_length length exceeds the length of string, the entire string is returned as the first (and only) array element.
* This function is aimed at replacing the function str_split() for human-language strings.
* @link http://php.net/str_split
*/
function api_str_split($string, $split_length = 1, $encoding = null)
{
return Utf8::str_split($string, $split_length);
}
示例4: utf8_str_split
/**
* Convert a string to an array
*
* @param string $str
*
* @return array
*
* @deprecated Deprecated since Contao 4.0, to be removed in Contao 5.0.
* Use Patchwork\Utf8::str_split() instead.
*/
function utf8_str_split($str)
{
@trigger_error('Using utf8_str_split() has been deprecated and will no longer work in Contao 5.0. Use Patchwork\\Utf8::str_split() instead.', E_USER_DEPRECATED);
return Utf8::str_split($str);
}
示例5: test_split_newline
public function test_split_newline()
{
$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->assertEquals($array, u::str_split($str));
}
示例6: 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);
/** @var SessionInterface $objSession */
$objSession = \System::getContainer()->get('session');
$objSession->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;
}
示例7: 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)
{
if (strpos($strString, '@') === false) {
return $strString;
}
$arrEmails = static::extractEmail($strString, \Config::get('allowedTags'));
foreach ($arrEmails 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);
}