当前位置: 首页>>代码示例>>PHP>>正文


PHP core_text::str_max_bytes方法代码示例

本文整理汇总了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);
 }
开发者ID:rushi963,项目名称:moodle,代码行数:44,代码来源:text_test.php

示例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);
 }
开发者ID:janeklb,项目名称:moodle,代码行数:12,代码来源:document.php


注:本文中的core_text::str_max_bytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。