Created
January 27, 2015 09:43
-
-
Save escapeboy/39ab26e35711f6fbce84 to your computer and use it in GitHub Desktop.
Laravel truncate text and preserve html tags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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