本文整理匯總了PHP中core_text::str_max_bytes方法的典型用法代碼示例。如果您正苦於以下問題:PHP core_text::str_max_bytes方法的具體用法?PHP core_text::str_max_bytes怎麽用?PHP core_text::str_max_bytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類core_text
的用法示例。
在下文中一共展示了core_text::str_max_bytes方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: test_str_max_bytes
/**
* Test unicode safe string truncation.
*/
public function test_str_max_bytes()
{
// These are all 3 byte characters, so this is a 12-byte string.
$str = '言語設定';
$this->assertEquals(12, strlen($str));
// Step back, shortening the string 1 byte at a time. Should remove in 1 char chunks.
$conv = core_text::str_max_bytes($str, 12);
$this->assertEquals(12, strlen($conv));
$this->assertSame('言語設定', $conv);
$conv = core_text::str_max_bytes($str, 11);
$this->assertEquals(9, strlen($conv));
$this->assertSame('言語設', $conv);
$conv = core_text::str_max_bytes($str, 10);
$this->assertEquals(9, strlen($conv));
$this->assertSame('言語設', $conv);
$conv = core_text::str_max_bytes($str, 9);
$this->assertEquals(9, strlen($conv));
$this->assertSame('言語設', $conv);
$conv = core_text::str_max_bytes($str, 8);
$this->assertEquals(6, strlen($conv));
$this->assertSame('言語', $conv);
// Now try a mixed byte string.
$str = '言語設a定';
$this->assertEquals(13, strlen($str));
$conv = core_text::str_max_bytes($str, 11);
$this->assertEquals(10, strlen($conv));
$this->assertSame('言語設a', $conv);
$conv = core_text::str_max_bytes($str, 10);
$this->assertEquals(10, strlen($conv));
$this->assertSame('言語設a', $conv);
$conv = core_text::str_max_bytes($str, 9);
$this->assertEquals(9, strlen($conv));
$this->assertSame('言語設', $conv);
$conv = core_text::str_max_bytes($str, 8);
$this->assertEquals(6, strlen($conv));
$this->assertSame('言語', $conv);
// Test 0 byte case.
$conv = core_text::str_max_bytes($str, 0);
$this->assertEquals(0, strlen($conv));
$this->assertSame('', $conv);
}
示例2: format_string_for_engine
/**
* Formats the timestamp according to the search engine needs.
*
* @param int $timestamp
* @return string
*/
public static function format_string_for_engine($string)
{
// 2^15 default. We could convert this to a setting as is possible to
// change the max in solr.
return \core_text::str_max_bytes($string, 32766);
}