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