Are there any best practices for efficiently handling string manipulation in PHP, such as limiting the length of displayed content?

When working with string manipulation in PHP, it's important to efficiently handle tasks such as limiting the length of displayed content to improve performance and user experience. One common approach is to use the `substr()` function to extract a portion of a string based on a specified length. Additionally, you can use functions like `strlen()` to determine the length of a string before manipulating it.

// Limit the length of a string and add ellipsis if it exceeds the limit
function limitString($string, $limit) {
    if(strlen($string) > $limit) {
        $string = substr($string, 0, $limit) . '...';
    }
    return $string;
}

// Example usage
$content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
echo limitString($content, 20); // Output: Lorem ipsum dolor si...