php trim a string -
php trim a string -
i'm trying build function trim string it's long per specifications.
here's have:
function trim_me($s,$max) { if (strlen($s) > $max) { $s = substr($s, 0, $max - 3) . '...'; } homecoming $s; }
the above trim string if it's longer $max
, add together continuation...
i want expand function handle multiple words. does, if have string say: how today?
18 characters long. if run trim_me($s,10)
show how yo...
, not aesthetically pleasing. how can create adds ...
after whole word. if run trim_me($s,10)
want display how you...
adding continuation after word. ideas?
i pretty much don't want add together continuation in middle of word. if string has 1 word, continuation can break word only.
so, here's want:
<?php // original php code chirp internet: www.chirp.com.au // please acknowledge utilize of code including header. function mytruncate($string, $limit, $break=".", $pad="...") { // $break nowadays between $limit , end of string? if(false !== ($breakpoint = strpos($string, $break, $limit))) { if($breakpoint < strlen($string) - 1) { $string = substr($string, 0, $breakpoint) . $pad; } } homecoming $string; } ?>
also, can read more @ http://www.the-art-of-web.com/php/truncate/
php string
Comments
Post a Comment