Created
May 12, 2020 07:57
-
-
Save andreipa/782209b08daecfc6ee60916540a18cff to your computer and use it in GitHub Desktop.
Remove html tags and truncate string adding a trim marker.
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
/** | |
* Remove html tags and truncate string | |
* | |
* @link https://www.php.net/manual/en/function.mb-strimwidth.php | |
* @author Andrei Andrade | |
* | |
* @param string $string The string being decoded. | |
* @param int $width The width of the desired trim. | |
* @param string $trimMarker A string that is added to the end of string when string is truncated. | |
* | |
* @return string | |
*/ | |
function truncate($string, $width, $trimMarker = '...') | |
{ | |
$string = trim(strip_tags($string)); | |
$string = mb_strimwidth($string, 0, $width, $trimMarker, "UTF-8"); | |
return $string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment