PHP: Keep HTML Tags Paired

After applying substr to a string that contains HTML tags, usually I found that the result is broken because the closing tags are truncated. To prevent this, I have made a function that keep the closing tags remains and will not break the appearance of my website. Here is the function: Usage/Example: Feedback and comment [...]