PHP functions:trim middle: Difference between revisions
(created description, status (pre-epsilon, haha), source, and why 33?) |
(two brackets required for Image) |
||
Line 46: | Line 46: | ||
== Why 33? == | == Why 33? == | ||
[Image:My_test_URL_is_33_characters_long.png] | [[Image:My_test_URL_is_33_characters_long.png]] |
Revision as of 21:05, 4 November 2007
Description
This PHP function will reduce long strings to shorter strings, by trimming out the middle. It can be used on any string, but was inspired by the need to reduce URLs that are
http://super.really.long.urls/so/long/they/cannot/really_fit_in_one/field,then
I'd like to reduce the middle of the URL to "[...]"
http://super.really.long.urls[...]/really_fit_in_one/field,then
The field will look a bit nicer and still have useful information.
Status
This code is in pre-epsilon status. Wait a few hours, or contact me if nothing happens in that amount of time Thunder Rabbit
Source
<source lang="php"> <?php //***********************************************// // // this code is freeware // //***********************************************//
/***********************************************/ // echo trim_middle("this is a long string", 10); // thi[...]ng /***********************************************/ function trim_middle($string, $len = 33, $center = "[...]") {
if(strlen($string) <= $len) { return($string); } else { return "too long"; } } ?> </source>