PHP Cut string from MySQL
Shorting or cutting the text string from long char into new max lenght.
Here is the code.
PHP CODE
function short_string ($var, $len){
if (strlen ($var) < $len) {
return $var;
}
if (preg_match ("/(.{1,$len})\s/", $var, $match)) {
return $match [1] . "..";
} else {
return substr ($var, 0, $len) . "..";
}
}
How to use?
PHPCODE
short_string ("Very very long text is here blablabla", 14);
The Result is:
Very very long..
No comments:
Post a Comment