- Impact
- 74
Hey,
I made this function and posted it at my blog, so, i thought i may aswell post it here too.
This is a simple functions to cut strings down to "My lastest project...", from " "My lastest project is a CMS".
Great for "Last Post" colums, descriptions, titles etc....
The code
You can choose what "pattern" to display, most common one is "...", remember, when adding the pattern into the function surround the pattern with " ", otherwise you could get errors.
If you decide to cut strings at 21 characters, if the string is below that, no pattern will be added.
I hope you find this useful when adding it into your scripts and projects, it's a general thing that gets left out alof of scripts alot of the time, but is very useful. :tu:
Adrian
I made this function and posted it at my blog, so, i thought i may aswell post it here too.
This is a simple functions to cut strings down to "My lastest project...", from " "My lastest project is a CMS".
Great for "Last Post" colums, descriptions, titles etc....
The code
PHP:
<?php
/*************************************
/ Function Name: Continued Strings
/ Function Description: This cuts a string, and adds a pattern to the end. (User defined patterns, and length)
/ Author: Adrian
/ Website: Dreamit.co.uk
*************************************/
function Cont_String($string, $length, $pattern){
if(strlen($string) > $length){
$final = substr("" . $string . "", 0, $length);
$final .= "" . $pattern . "";
return $final;
} else {
return $string;
}
}
$about = "Hello, my name is Adrian and i own Dreamit.co.uk";
$display = Cont_String($about, 21, "...");
echo $display;
?>
You can choose what "pattern" to display, most common one is "...", remember, when adding the pattern into the function surround the pattern with " ", otherwise you could get errors.
If you decide to cut strings at 21 characters, if the string is below that, no pattern will be added.
I hope you find this useful when adding it into your scripts and projects, it's a general thing that gets left out alof of scripts alot of the time, but is very useful. :tu:
Adrian







