What potential issues or limitations were highlighted in the use of regular expressions for truncating a string in the PHP forum thread discussion?

The potential issues highlighted in the use of regular expressions for truncating a string in the PHP forum thread discussion were that it may not handle multibyte characters properly, leading to unexpected results or errors. To solve this issue, it is recommended to use the mb_substr function in PHP, which is specifically designed to handle multibyte characters when truncating strings.

function truncate_string($string, $length) {
    if(mb_strlen($string) > $length) {
        $string = mb_substr($string, 0, $length) . '...';
    }
    return $string;
}

// Example usage
$string = "Hello, こんにちは";
$truncated_string = truncate_string($string, 10);
echo $truncated_string; // Output: Hello, こ...