• 0

PHP text cut function question


Question

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) &lt;= $limit) return $string;

  // is $break present between $limit and the end of the string?
  if(false !== ($breakpoint = strpos($string, $break, $limit))) {
    if($breakpoint &lt; 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

There have been no answers to this question yet

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.