[ create a new paste ] login | about

Link: http://codepad.org/HOvZXxVP    [ raw code | output | fork ]

PHP, pasted on Sep 21:
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php

function cutAfter($string, $len = 30, $append = '...') {
        return (strlen($string) > $len) ? 
          substr($string, 0, $len - strlen($append)) . $append : 
          $string;
}

echo cutAfter('foo bar baz', 2)."\n";
echo cutAfter('foo bar baz', 10)."\n";
echo cutAfter('foo bar baz', 11)."\n";

echo cutAfter('foo bar baz', 6, '!!!')."\n";


Output:
1
2
3
4
foo bar ba...
foo bar...
foo bar baz
foo!!!


Create a new paste based on this one


Comments: