Link to home
Create AccountLog in
Avatar of BrighteyesDesign
BrighteyesDesignFlag for Afghanistan

asked on

Remove spaces from truncated text

I am truncate some text using...

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;
}

Open in new window



echo myTruncate($row_Recordset1['copy'], 300);

Open in new window


However I need to strip the text of <p>, <br> etc... as the current results can leave white spaces


User generated image
So the text from the screenshot above should show as...

Dear Friends I write to let you know the arrangements which have been agreed by the Archbishop of Canterbury for the See of Ebbsfleet during the vacancy. The Bishop of Plymouth (Bishop John Ford) and Bishop Lindsay Urwin have accepted the Archbishop’s invitation to be available to the clergy and parishes who look to the Bishop of Ebbsfleet for extended episcopal care until a new Bishop is in place...

Any ideas how to achieve this?
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

You need to apply the function:
http://php.net/manual/en/function.strip-tags.php
Avatar of BrighteyesDesign

ASKER

Great thanks!

Sorry to be dense, but how to I integrate that with the code i'm currently using?
return strip_tags($string);
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Perfect, thanks a million