-
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Formatter feature request (text limit / word wrap) #3
Comments
Thanks @lynicidn, but none method form this class cover my case. |
show how you use it |
Example: $this->title = Yii::t('app', 'Update: {question}', [
'question' => StringHelper::truncate($model->question, 20)
]); In question is string: |
@lynicidn I do not know how many words should be printed. It depends on word lengths. |
@mklemarczyk ok, you right - i don't help for you - sorry. simple way use truncate + find "white space of end" and apply endWith ('white space + partword + ...') |
Here is what you need. strrpos with negative limit finds last space in string before the limit. function truncate($string, $limit)
{
return substr($string, 0, strrpos($string, ' ', $limit - strlen($string)));
}
echo truncate('Do you like drink coffee at work?', 20); Output is 'Do you like drink' |
StringHelper::truncateWords() is available since Yii 2.0.1 |
as far as I understood the request it was to truncate words based on a maximum string length. StringHelper::truncateWords() is based on word count. |
I do not have concept to implement this thing, but I think that it can be extension to asText formatter method.
First, there are a few methods of word wrapping:
I want use word wrapping to limit text.
I know that I should use
substr
, but this method will break last word.There is also
wordwrap
, but first it does have third wrapping method, and secondly it only insert break line character.This feature can be used in:
The text was updated successfully, but these errors were encountered: