str()

str_为前缀的函数执行在处理字符串时有用的任务。 帮助程序直接映射到Str PHP类及其方法。 例如:

  1. {{ str_camel() }}

对应的PHP的方法如下:

  1. <?= Str::camel() ?>

注意: camelCase驼峰命名中的方法应转换为snake_case下划线命名

str_limit()

限制字符串中的字符数。

  1. {{ str_limit('The quick brown fox...', 100) }}

要在应用限制时添加后缀,请将其作为第三个参数传递。 默认为“…”。

  1. {{ str_limit('The quick brown fox...', 100, '... Read more!') }}

str_words()

限制字符串中的单词数。

  1. {{ str_words('The quick brown fox...', 100) }}

要在应用限制时添加后缀,请将其作为第三个参数传递。 默认为“…”。

  1. {{ str_words('The quick brown fox...', 100, '... Read more!') }}

str_camel()

将值转换为camelCase

  1. // 输出: helloWorld
  2. {{ str_camel('hello world') }}

str_studly()

将值转换为StudlyCase

  1. // 输出: HelloWorld
  2. {{ str_studly('hello world') }}

str_snake()

将值转换为snake_case

  1. // 输出: hello_world
  2. {{ str_snake('hello world') }}

第二个参数可以提供分隔符。

  1. // 输出: hello---world
  2. {{ str_snake('hello world', '---') }}

str_plural()

获取复数形式的英文单词。

  1. // 输出: chickens
  2. {{ str_plural('chicken') }}