Skip to content

Instantly share code, notes, and snippets.

View jakobtrost's full-sized avatar

Jakob Trost jakobtrost

View GitHub Profile
@getmanzooronline
getmanzooronline / php_substring_html.php
Last active September 10, 2023 20:53
PHP Substring without breaking words and HTML tags
<?php
/**
* Truncates text.
*
* Cuts a string to the length of $length and replaces the last characters
* with the ending if the text is longer than length.
*
* @param string $text String to truncate.
* @param integer $length Length of returned string, including ellipsis.
* @param string $ending Ending to be appended to the trimmed string.