本文整理匯總了PHP中Zend\Stdlib\StringUtils::isSingleByteEncoding方法的典型用法代碼示例。如果您正苦於以下問題:PHP StringUtils::isSingleByteEncoding方法的具體用法?PHP StringUtils::isSingleByteEncoding怎麽用?PHP StringUtils::isSingleByteEncoding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Stdlib\StringUtils
的用法示例。
在下文中一共展示了StringUtils::isSingleByteEncoding方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: strPad
/**
* Pad a string to a certain length with another string
*
* @param string $input
* @param integer $padLength
* @param string $padString
* @param integer $padType
* @return string
*/
public function strPad($input, $padLength, $padString = ' ', $padType = STR_PAD_RIGHT)
{
if (StringUtils::isSingleByteEncoding($this->getEncoding())) {
return str_pad($input, $padLength, $padString, $padType);
}
$lengthOfPadding = $padLength - $this->strlen($input);
if ($lengthOfPadding <= 0) {
return $input;
}
$padStringLength = $this->strlen($padString);
if ($padStringLength === 0) {
return $input;
}
$repeatCount = floor($lengthOfPadding / $padStringLength);
if ($padType === STR_PAD_BOTH) {
$lastStringLeft = '';
$lastStringRight = '';
$repeatCountLeft = $repeatCountRight = ($repeatCount - $repeatCount % 2) / 2;
$lastStringLength = $lengthOfPadding - 2 * $repeatCountLeft * $padStringLength;
$lastStringLeftLength = $lastStringRightLength = floor($lastStringLength / 2);
$lastStringRightLength += $lastStringLength % 2;
$lastStringLeft = $this->substr($padString, 0, $lastStringLeftLength);
$lastStringRight = $this->substr($padString, 0, $lastStringRightLength);
return str_repeat($padString, $repeatCountLeft) . $lastStringLeft . $input . str_repeat($padString, $repeatCountRight) . $lastStringRight;
}
$lastString = $this->substr($padString, 0, $lengthOfPadding % $padStringLength);
if ($padType === STR_PAD_LEFT) {
return str_repeat($padString, $repeatCount) . $lastString . $input;
}
return $input . str_repeat($padString, $repeatCount) . $lastString;
}
示例2: testIsSingleByteEncodingReturnsFalse
/**
* @dataProvider getNonSingleByteEncodings
* @param string $encoding
*/
public function testIsSingleByteEncodingReturnsFalse($encoding)
{
$this->assertFalse(StringUtils::isSingleByteEncoding($encoding));
}