本文整理汇总了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));
}