maybe someone can help me out. i have a function that cuts the text that is longer than 300 chars. my problem is that if i cut the string and it contains <object> - eg a youtube video - then the function cuts it, too. now what i want is the function not to cut string if it's longer than 300 chars because of the object but cut it if the chars after the </object> tag are longer than 300 chars.
here's the function:
function myTruncate($string, $limit, $break=".", $pad="...")
{
// return with no change if string is shorter than $limit
if(strlen($string) <= $limit) return $string;
// is $break present between $limit and the end of the string?
if(false !== ($breakpoint = strpos($string, $break, $limit))) {
if($breakpoint < strlen($string) - 1) {
$string = substr($string, 0, $breakpoint) . $pad;
}
}
return $string;
}
Question
GeeQ
Hello Guys,
maybe someone can help me out. i have a function that cuts the text that is longer than 300 chars. my problem is that if i cut the string and it contains <object> - eg a youtube video - then the function cuts it, too. now what i want is the function not to cut string if it's longer than 300 chars because of the object but cut it if the chars after the </object> tag are longer than 300 chars.
here's the function:
function myTruncate($string, $limit, $break=".", $pad="...") { // return with no change if string is shorter than $limit if(strlen($string) <= $limit) return $string; // is $break present between $limit and the end of the string? if(false !== ($breakpoint = strpos($string, $break, $limit))) { if($breakpoint < strlen($string) - 1) { $string = substr($string, 0, $breakpoint) . $pad; } } return $string; }thanks for the help!
GQ
Link to comment
Share on other sites
0 answers to this question
Recommended Posts