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
459b2165
Commit
459b2165
authored
Oct 11, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #111 from ericbarnes/feature/str_limit
Feature/str limit
parents
d0771493
ba4fd3fa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
0 deletions
+49
-0
str.php
laravel/str.php
+49
-0
No files found.
laravel/str.php
View file @
459b2165
...
@@ -98,6 +98,55 @@ class Str {
...
@@ -98,6 +98,55 @@ class Str {
return
strlen
(
$value
);
return
strlen
(
$value
);
}
}
/**
* Limit the number of chars in a string
*
* <code>
* // Limit the characters
* echo Str::limit_chars('taylor otwell', 3);
* results in 'tay...'
* </code>
*
* @param string $value
* @param int $length
* @param string $end
* @return string
*/
public
static
function
limit
(
$value
,
$length
=
100
,
$end
=
'...'
)
{
if
(
static
::
length
(
$value
)
<=
$length
)
return
$value
;
if
(
function_exists
(
'mb_substr'
))
{
return
mb_substr
(
$value
,
0
,
$length
)
.
$end
;
}
return
substr
(
$value
,
0
,
$length
)
.
$end
;
}
/**
* Limit the number of words in a string
*
* <code>
* // Limit the words
* echo Str::limit_chars('This is a sentence.', 3);
* results in 'This is a...'
* </code>
*
* @param string $value
* @param int $length
* @param string $end
* @return string
*/
public
static
function
limit_words
(
$value
,
$length
=
100
,
$end
=
'...'
)
{
$count
=
str_word_count
(
$value
,
1
);
if
(
$count
<=
$length
)
return
$value
;
return
implode
(
' '
,
array_slice
(
$count
,
0
,
$length
))
.
$end
;
}
/**
/**
* Convert a string to 7-bit ASCII.
* Convert a string to 7-bit ASCII.
*
*
...
...
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