字符串

camel_case

把给定的字串转换成 驼峰式命名。

$camel = camel_case("foo_bar");

// fooBar

class_basename

取得给定类的类名称,不含任何命名空间的名称。

$class = class_basename("FooBarBaz");

// Baz

e

对给定字串执行 htmlentities,并支持 UTF-8。

$entities = e("<html>foo</html>");

ends_with

判断句子结尾是否有给定的字串。

$value = ends_with("This is my name", "name");

snake_case

把给定的字串转换成 蛇形命名。

$snake = snake_case("fooBar");

// foo_bar

str_limit

限制字串的字符数量。

str_limit($value, $limit = 100, $end = "...")

例子:

$value = str_limit("The PHP framework for web artisans.", 7);

// The PHP...

starts_with

判断句子是否开头有给定的字串。

$value = starts_with("This is my name", "This");

str_contains

判断句子是否有给定的字串。

$value = str_contains("This is my name", "my");

str_finish

加一个给定字串到句子结尾。多余一个的给定字串则移除。

$string = str_finish("this/string", "/");

// this/string/

str_is

判断字串是否符合给定的模式。星号可以用来当作通配符。

$value = str_is("foo*", "foobar");

str_plural

把字串转换成它的多数形态 (只有英文)。

$plural = str_plural("car");

str_random

产生给定长度的随机字串。

$string = str_random(40);

str_singular

把字串转换成它的单数形态 (只有英文)。

$singular = str_singular("cars");

str_slug

从给定字串产生一个对网址友善的「slug」。

str_slug($title, $separator);

例子:

$title = str_slug("Laravel 5 Framework", "-");

// laravel-5-framework

studly_case

把给定字串转换成 首字大写命名。

$value = studly_case("foo_bar");

// FooBar

trans

翻译给定的语句。等同 Lang::get。

$value = trans("validation.required"):

trans_choice

随着词形变化翻译给定的语句。等同 Lang::choice。

$value = trans_choice("foo.bar", $count);

文章导航