What are the potential pitfalls of using substr() function in PHP when dealing with variable-length numbers?

When using the substr() function in PHP to extract a substring from a variable-length number, a potential pitfall is that it may not work correctly if the length of the number varies. This can lead to unexpected results or errors in your code. To solve this issue, you can use the preg_replace() function with a regular expression pattern to extract the desired substring from the number, regardless of its length.

$number = '123456789';
$substring = preg_replace('/^(\d{3})/', '$1', $number);
echo $substring; // Output: 123