本文整理汇总了PHP中JString::str_split方法的典型用法代码示例。如果您正苦于以下问题:PHP JString::str_split方法的具体用法?PHP JString::str_split怎么用?PHP JString::str_split使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JString
的用法示例。
在下文中一共展示了JString::str_split方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: safe
/**
* Safe String. Remove no letter's, no number's and other's no allowed Signs.
*
* @param string $string String to safe
* @return string
*/
public static function safe($string)
{
static $items;
if (is_null($items)) {
$letters[] = 'abcdefghijklmnopqrstuvwxyz';
$letters[] = 'áćéǵíḱĺḿńóṕŕśúǘẃýź';
$letters[] = 'äëḧïöẗüẅẍÿ';
$letters[] = 'åůẘẙ';
$letters[] = 'ǎčďěǧȟǐǰǩľňǒřšťǔǚž';
$letters[] = '.-_ ';
$items = array();
foreach ($letters as $item) {
$items = array_merge($items, parent::str_split($item), parent::str_split(parent::strtoupper($item)));
}
$items = array_merge($items, parent::str_split('0123456789'));
}
$string = parent::str_split($string);
$safe = '';
foreach ($string as $item) {
if (in_array($item, $items)) {
$safe .= $item;
}
}
return parent::trim($safe);
}
示例2: translate
/**
* Translate a long text by Google, if it too long, will separate it..
*
* @param string $text String to translate.
* @param string $SourceLan Translate from this language, eg: 'zh-tw'. Empty will auto detect.
* @param string $ResultLan Translate to this language, eg: 'en'. Empty will auto detect.
* @param integer $separate Separate text by a number of words, batch translate them and re combine to return.
*
* @return string Translated text.
*/
public static function translate($text, $SourceLan = null, $ResultLan = null, $separate = 0)
{
// If text too big, separate it.
if ($separate) {
if (\JString::strlen($text) > $separate) {
$text = \JString::str_split($text, $separate);
} else {
$text = array($text);
}
} else {
$text = array($text);
}
$result = '';
// Do translate by google translate API.
foreach ($text as $txt) {
$result .= self::gTranslate($txt, $SourceLan, $ResultLan);
}
return $result;
}
示例3: testStr_split
/**
* @group String
* @covers JString::str_split
* @dataProvider str_splitData
*/
public function testStr_split($string, $split_length, $expect)
{
$actual = JString::str_split($string, $split_length);
$this->assertEquals($expect, $actual);
}
示例4: censureWords
/**
* Parse the content by censoring blacklisted words.
* Borrowed from php-decoda.
*
* @param string $content
* @return string
*/
public function censureWords($content)
{
$censored = $this->params->get('censored_words', '');
$censored = array_filter(array_map(array('JString', 'trim'), explode(',', $censored)));
foreach ($censored as $word) {
$letters = JString::str_split($word);
$regex = '';
foreach ($letters as $letter) {
$regex .= preg_quote($letter, '/') . '{1,}';
}
$content = preg_replace_callback('/(^|\\s|\\n)?' . $regex . '(\\s|\\n|$)?/is', array($this, '_censorCallback'), $content);
}
return $content;
}