Skip to content

Instantly share code, notes, and snippets.

@escapeboy
Created January 27, 2015 09:43
Show Gist options
  • Save escapeboy/39ab26e35711f6fbce84 to your computer and use it in GitHub Desktop.
Save escapeboy/39ab26e35711f6fbce84 to your computer and use it in GitHub Desktop.
Laravel truncate text and preserve html tags
<?php
public function substr_text_only($string, $limit, $end='...')
{
$with_html_count = strlen($string);
$without_html_count = strlen(strip_tags($string));
$html_tags_length = $with_html_count-$without_html_count;
return str_limit($string, $limit+$html_tags_length, $end);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment