Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
b73a60de
Commit
b73a60de
authored
Feb 15, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rearrange str class.
parent
ab17ea67
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
28 deletions
+28
-28
str.php
laravel/str.php
+28
-28
No files found.
laravel/str.php
View file @
b73a60de
...
...
@@ -123,6 +123,34 @@ class Str {
return
substr
(
$value
,
0
,
$limit
)
.
$end
;
}
/**
* Limit the number of words in a string.
*
* <code>
* // Returns "This is a..."
* echo Str::words('This is a sentence.', 3);
*
* // Limit the number of words and append a custom ending
* echo Str::words('This is a sentence.', 3, '---');
* </code>
*
* @param string $value
* @param int $words
* @param string $end
* @return string
*/
public
static
function
words
(
$value
,
$words
=
100
,
$end
=
'...'
)
{
preg_match
(
'/^\s*+(?:\S++\s*+){1,'
.
$words
.
'}/'
,
$value
,
$matches
);
if
(
static
::
length
(
$value
)
==
static
::
length
(
$matches
[
0
]))
{
$end
=
''
;
}
return
rtrim
(
$matches
[
0
])
.
$end
;
}
/**
* Get the singular form of the given word.
*
...
...
@@ -166,34 +194,6 @@ class Str {
return
(
ctype_upper
(
$value
[
0
]))
?
static
::
title
(
$plural
)
:
$plural
;
}
/**
* Limit the number of words in a string.
*
* <code>
* // Returns "This is a..."
* echo Str::words('This is a sentence.', 3);
*
* // Limit the number of words and append a custom ending
* echo Str::words('This is a sentence.', 3, '---');
* </code>
*
* @param string $value
* @param int $words
* @param string $end
* @return string
*/
public
static
function
words
(
$value
,
$words
=
100
,
$end
=
'...'
)
{
preg_match
(
'/^\s*+(?:\S++\s*+){1,'
.
$words
.
'}/'
,
$value
,
$matches
);
if
(
static
::
length
(
$value
)
==
static
::
length
(
$matches
[
0
]))
{
$end
=
''
;
}
return
rtrim
(
$matches
[
0
])
.
$end
;
}
/**
* Generate a URL friendly "slug" from a given string.
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment