Delimits a portion of text to the number of "words":
1 2 3 4 5 6 7 8 9 10 11 | / ** * String word cut * * @ Private * / $c , $l ) { wordCut function ($ c, $ s) { explode ( ' ' , $c ) ; $ C = explode ('', $ c); $i = 0 ; $i < $l ; $i ++ ) $r [ $i ] = $c [ $i ] ; for ($ i = 0; $ i <$ l $ i + +) $ r [$ i] = $ c [$ i]; implode ( ' ' , $r ) . '...' ; $ R = implode ('', $ r).'...'; ; return $ r; } |










From 2 lines for a esempiuccio you could do it.
My tagliaStringa ($ string, $ numParole) is a bit 'different ... I do not use two arrays, but build the string by inserting the words as in a variable, then cutting off the last space and adding the three dots ...
What do you say?
Thank you! Carpita and used ...
LOL!
@ Tom: oh my God, an example for a function "string size" is a bit 'too ...
However, for example, you can use to:
You will get in the
$res:Sample string long enough ...@ Napolux: I searched in vain for your function to your blog ... cmq even so would be fine:
2
3
4
5
explode ( ' ' , $c ) ; $ C = explode ('', $ c);
$i = 0 ; $i < $l ; $i ++ ) $r [ $i ] = ( $i == 0 ) ? $c [ $i ] : ( ' ' . $c [ $i ] ) ; for ($ i = 0; $ i <$ l $ i + +) $ r [$ i] = ($ i == 0)? $ c [$ i]: ('.' $ c [$ i] );
$r . '...' ) ; return ($ r.'...');
}
Note the "gem" for not trying to eliminate the extra space
@ Julius: I pray dear! Although no one realized that the proper function for large string would be:
2
3
4
5
6
7
8
explode ( ' ' , $c ) ; $ A = explode ('', $ c);
count ( $a ) > $l ) { if ( count ($ a)> $ l) {
$i = 0 ; $i < $l ; $i ++ ) $r [ $i ] = $a [ $i ] ; for ($ i = 0; $ i <$ l $ i + +) $ r [$ i] = $ a [$ i];
implode ( ' ' , $r ) . '...' ; $ R = implode ('', $ r).'...';
; return $ r;
$c ; Else return $ c};
}
N'en pas plus je say:
http://fr.php.net/manual/fr/function.substr.php
et pour finish an EXAMPLE:
http://www.destrucsaweb.com/ressources/phpmyannu/goto_38.php
A +
[...] Already seen Very short snippet: PHP is more pleasant to break word cut a text to "words", as it avoids cutting a word. There is [...]