Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Text richtig kuerzen nach jedem Wort und nicht mitten drin

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
Conny64
Smarty Rookie


Joined: 10 Mar 2016
Posts: 5

PostPosted: Thu Mar 10, 2016 9:43 am    Post subject: Text richtig kuerzen nach jedem Wort und nicht mitten drin Reply with quote

Hi, ich habe folgenden PHP snippet gefunden
und würde das gerne in Smarty machen.

Kann jemand einer Anfängerin helfen ?
$string = Der Text der abgeschnitten werden soll.
$length = Nach wie vielen Zeichen soll der Text abgeschnitten werden.
Code:

$string = preg_replace("/[^ ]*$/", '', substr($string, 0, $length));

Info hier:
http://www.gordonzube.com/2012/01/27/php-text-richtig-kuerzen-nach-dem-wort-nicht-mittendrin.html
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Mar 10, 2016 2:56 pm    Post subject: Reply with quote

Das gibt es schon als modifier truncate.
Siehe http://www.smarty.net/docs/en/language.modifier.truncate.tpl

zB.
Code:
{$foo|truncate:20}

Per default fügt truncate bei einer Kürzung am Ende '...' an.
Ist das nicht gewünscht dann
Code:
{$foo|truncate:20:''}
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP