What are the potential pitfalls of using substr() and strlen() functions in PHP for string manipulation?

Using substr() and strlen() functions for string manipulation in PHP can lead to potential pitfalls such as off-by-one errors and inefficient code. To avoid these issues, it's recommended to use the mb_substr() and mb_strlen() functions instead, especially when working with multibyte characters or different character encodings.

// Using mb_substr() and mb_strlen() for safe string manipulation
$string = "Hello, 你好";
$substring = mb_substr($string, 0, 5, 'UTF-8');
$length = mb_strlen($string, 'UTF-8');

echo $substring; // Output: Hello
echo $length; // Output: 9