企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 字符串助手函数 ### [](https://octobercms.com/docs/services/helpers#strings)弦乐 #### [](https://octobercms.com/docs/services/helpers#method-camel-case)`camel_case()` 该`camel_case`函数将给定的字符串转换为`camelCase`: ~~~ $camel = camel_case('foo_bar'); // fooBar ~~~ #### [](https://octobercms.com/docs/services/helpers#method-class-basename)`class_basename()` 该`class_basename`收益与类的命名空间中的给定类的类名称中删除: ~~~ $class = class_basename('Foo\Bar\Baz'); // Baz ~~~ #### [](https://octobercms.com/docs/services/helpers#method-e)`e()` 该`e`函数`htmlentities`在给定的字符串上运行: ~~~ echo e('<html>foo</html>'); // &lt;html&gt;foo&lt;/html&gt; ~~~ #### [](https://octobercms.com/docs/services/helpers#method-ends-with)`ends_with()` 该`ends_with`函数确定给定的字符串是否以给定的值结尾: ~~~ $value = ends_with('This is my name', 'name'); // true ~~~ #### [](https://octobercms.com/docs/services/helpers#method-snake-case)`snake_case()` 该`snake_case`函数将给定的字符串转换为`snake_case`: ~~~ $snake = snake_case('fooBar'); // foo_bar ~~~ #### [](https://octobercms.com/docs/services/helpers#method-str-limit)`str_limit()` 该`str_limit`函数限制字符串中的字符数。该函数将字符串作为第一个参数,并将最大字符数作为第二个参数: ~~~ $value = str_limit('The CMS platform that gets back to basics.', 6); // The CMS... ~~~ #### [](https://octobercms.com/docs/services/helpers#method-starts-with)`starts_with()` 该`starts_with`函数确定给定的字符串是否以给定的值开头: ~~~ $value = starts_with('The cow goes moo', 'The'); // true ~~~ #### [](https://octobercms.com/docs/services/helpers#method-str-contains)`str_contains()` 该`str_contains`函数确定给定的字符串是否包含给定的值: ~~~ $value = str_contains('The bird goes tweet', 'bird'); // true ~~~ #### [](https://octobercms.com/docs/services/helpers#method-str-finish)`str_finish()` 该`str_finish`函数将给定值的单个实例添加到字符串中: ~~~ $string = str_finish('this/string', '/'); // this/string/ ~~~ #### [](https://octobercms.com/docs/services/helpers#method-str-is)`str_is()` 该`str_is`函数确定给定的字符串是否匹配给定的模式。星号可用于表示通配符: ~~~ $value = str_is('foo*', 'foobar'); // true $value = str_is('baz*', 'foobar'); // false ~~~ #### [](https://octobercms.com/docs/services/helpers#method-str-plural)`str_plural()` 该`str_plural`函数将字符串转换为其复数形式。此功能目前仅支持英语: ~~~ $plural = str_plural('car'); // cars $plural = str_plural('child'); // children ~~~ #### [](https://octobercms.com/docs/services/helpers#method-str-random)`str_random()` 该`str_random`函数生成指定长度的随机字符串: ~~~ $string = str_random(40); ~~~ #### [](https://octobercms.com/docs/services/helpers#method-str-singular)`str_singular()` 该`str_singular`函数将字符串转换为单数形式。此功能目前仅支持英语: ~~~ $singular = str_singular('cars'); // car ~~~ #### [](https://octobercms.com/docs/services/helpers#method-str-slug)`str_slug()` 该`str_slug`函数从给定的字符串生成URL友好的“ slug”: ~~~ $title = str_slug("October CMS", "-"); // october-cms ~~~ #### [](https://octobercms.com/docs/services/helpers#method-studly-case)`studly_case()` 该`studly_case`函数将给定的字符串转换为`StudlyCase`: ~~~ $value = studly_case('foo_bar'); // FooBar ~~~ #### [](https://octobercms.com/docs/services/helpers#method-trans)`trans()` 该`trans`函数使用您的[本地化文件](https://octobercms.com/docs/plugin/localization)翻译给定的语言行: ~~~ echo trans('validation.required'): ~~~ #### [](https://octobercms.com/docs/services/helpers#method-trans-choice)`trans_choice()` 该`trans_choice`函数使用拐点翻译给定的语言行: ~~~ $value = trans_choice('foo.bar', $count); ~~~