You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: laravel/documentation/strings.md
+15-6Lines changed: 15 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -14,22 +14,29 @@
14
14
The **Str** class also provides three convenient methods for manipulating string capitalization: **upper**, **lower**, and **title**. These are more intelligent versions of the PHP [strtoupper](http://php.net/manual/en/function.strtoupper.php), [strtolower](http://php.net/manual/en/function.strtolower.php), and [ucwords](http://php.net/manual/en/function.ucwords.php) methods. More intelligent because they can handle UTF-8 input if the [multi-byte string](http://php.net/manual/en/book.mbstring.php) PHP extension is installed on your web server. To use them, just pass a string to the method:
15
15
16
16
echo Str::lower('I am a string.');
17
+
// i am a string.
17
18
18
19
echo Str::upper('I am a string.');
20
+
// I AM A STRING.
19
21
20
22
echo Str::title('I am a string.');
23
+
// I Am A String.
21
24
22
25
<aname="limits"></a>
23
26
## Word & Character Limiting
24
27
25
28
#### Limiting the number of characters in a string:
26
29
27
-
echo Str::limit($string, 10);
28
-
echo Str::limit_exact($string, 10);
30
+
echo Str::limit("Lorem ipsum dolor sit amet", 10);
31
+
// Lorem ipsu...
32
+
33
+
echo Str::limit_exact("Lorem ipsum dolor sit amet", 10);
34
+
// Lorem i...
29
35
30
36
#### Limiting the number of words in a string:
31
37
32
-
echo Str::words($string, 10);
38
+
echo Str::words("Lorem ipsum dolor sit amet", 3);
39
+
// Lorem ipsum dolor...
33
40
34
41
<aname="random"></a>
35
42
## Generating Random Strings
@@ -45,17 +52,17 @@ The **Str** class also provides three convenient methods for manipulating string
45
52
<aname="singular-and-plural"></a>
46
53
## Singular & Plural
47
54
48
-
The String class is capable of transforming your strings from singular to plural, and vice versa.
49
-
50
55
#### Getting the plural form of a word:
51
56
52
57
echo Str::plural('user');
58
+
// users
53
59
54
60
#### Getting the singular form of a word:
55
61
56
62
echo Str::singular('users');
63
+
// user
57
64
58
-
#### Getting the plural form if given value is greater than one:
65
+
#### Getting the plural form if specified value is greater than one:
59
66
60
67
echo Str::plural('comment', count($comments));
61
68
@@ -65,8 +72,10 @@ The String class is capable of transforming your strings from singular to plural
65
72
#### Generating a URL friendly slug:
66
73
67
74
return Str::slug('My First Blog Post!');
75
+
// my-first-blog-post
68
76
69
77
#### Generating a URL friendly slug using a given separator:
0 commit comments