What is the purpose of using the substr() function in the provided PHP code?

The purpose of using the substr() function in the provided PHP code is to extract a portion of a string starting from a specified position. This can be useful for manipulating strings, such as truncating a string to a certain length or extracting specific parts of it.

// Extract the first 10 characters of the string $text
$text = "Hello, World!";
$extracted_text = substr($text, 0, 10);

echo $extracted_text; // Output: Hello, Wor