Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
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
PSDI Army
yii2
Commits
87c002d5
Commit
87c002d5
authored
Nov 25, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #6207: Added support for truncating HTML strings using…
Fixes #6207: Added support for truncating HTML strings using `StringHelper::truncate()` and `StringHelper::truncateWords()`
parent
b2797b03
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
4 deletions
+5
-4
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
BaseStringHelper.php
framework/helpers/BaseStringHelper.php
+4
-4
No files found.
framework/CHANGELOG.md
View file @
87c002d5
...
...
@@ -58,6 +58,7 @@ Yii Framework 2 Change Log
-
Enh #5954:
`yii message`
command now shows user friendly error if it's not able to parse source file (samdark)
-
Enh #5983: Added
`Inflector::sentence()`
(pana1990, qiangxue)
-
Enh #6113: Improved debugger configuration and request UI (schmunk42)
-
Enh #6207: Added support for truncating HTML strings using
`StringHelper::truncate()`
and
`StringHelper::truncateWords()`
(Alex-Code)
-
Enh:
`Console::confirm()`
now uses
`Console::stdout()`
instead of
`echo`
to be consistent with all other functions (cebe)
-
Enh:
`yii\rbac\DbManager`
migration now uses database component specified in component settings instead of always using default
`db`
(samdark)
-
Enh: Added
`yii\base\Controller::renderContent()`
(qiangxue)
...
...
framework/helpers/BaseStringHelper.php
View file @
87c002d5
...
...
@@ -98,7 +98,7 @@ class BaseStringHelper
* @param integer $length How many characters from original string to include into truncated string.
* @param string $suffix String to append to the end of truncated string.
* @param string $encoding The charset to use, defaults to charset currently used by application.
* @param boolean $asHtml
If the string contains HTML set this to true to preserve it.
* @param boolean $asHtml
Whether to treat the string being truncated as HTML and preserve proper HTML tags
* @return string the truncated string.
*/
public
static
function
truncate
(
$string
,
$length
,
$suffix
=
'...'
,
$encoding
=
null
,
$asHtml
=
false
)
...
...
@@ -120,7 +120,7 @@ class BaseStringHelper
* @param string $string The string to truncate.
* @param integer $count How many words from original string to include into truncated string.
* @param string $suffix String to append to the end of truncated string.
* @param boolean $asHtml
If the string contains HTML set this to true to preserve it.
* @param boolean $asHtml
Whether to treat the string being truncated as HTML and preserve proper HTML tags
* @return string the truncated string.
*/
public
static
function
truncateWords
(
$string
,
$count
,
$suffix
=
'...'
,
$asHtml
=
false
)
...
...
@@ -143,10 +143,10 @@ class BaseStringHelper
* @param string $string The string to truncate
* @param integer $count
* @param string $suffix String to append to the end of the truncated string.
* @param string $encoding
* @param string
|boolean
$encoding
* @return string
*/
pr
ivate
static
function
truncateHtml
(
$string
,
$count
,
$suffix
,
$encoding
=
false
)
pr
otected
static
function
truncateHtml
(
$string
,
$count
,
$suffix
,
$encoding
=
false
)
{
$config
=
\HTMLPurifier_Config
::
create
(
null
);
$lexer
=
\HTMLPurifier_Lexer
::
create
(
$config
);
...
...
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