Shoutbox

PHP help ... again - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: PHP help ... again (/showthread.php?tid=62453)

PHP help ... again by absorbation on 07-03-2006 at 06:42 PM

After that script I had trouble with, the problem was sloved by a typo after like 2 hours so I am a little pissed off atm. Anyway can someone give me a function name for taking a peice of text (like http://reallllllllllllllllllylonglink.com) and change it to (http://reallllllllll...), what function would I use for this? :P Thanks :)


RE: PHP help ... again by Plik on 07-03-2006 at 06:51 PM

Heres a quick function i made.
All it does is take X chars from your string using substr and then sticks something on the end

code:
function shorten($string, $chars, $append = '...'){
   return substr($string, 0, $chars) . $append;
}
Params:
$string - The string you want shortened
$chars - The output length (not including what you stick on the end)
$append (optional) - What you want put on the end, defaults to ...

Examples
echo shorten('foobar', 3);
will output "foo..." (without quotes)

echo shorten('eljelly really rocks', 8, 'sucks');
will ouput "eljelly sucks" (without quotes)
RE: PHP help ... again by absorbation on 07-03-2006 at 06:53 PM

quote:
Originally posted by Plik
substr

Thats the word I needed, and now I have my script done. H-Master just told me on messenger. Thanks for your help though :).