BrighteyesDesign
asked on
Remove spaces from truncated text
I am truncate some text using...
However I need to strip the text of <p>, <br> etc... as the current results can leave white spaces
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?
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;
}
echo myTruncate($row_Recordset1['copy'], 300);
However I need to strip the text of <p>, <br> etc... as the current results can leave white spaces
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?
ASKER
Great thanks!
Sorry to be dense, but how to I integrate that with the code i'm currently using?
Sorry to be dense, but how to I integrate that with the code i'm currently using?
return strip_tags($string);
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Perfect, thanks a million
http://php.net/manual/en/function.strip-tags.php