How can the substr() function in PHP be used to extract a portion of a string up to a certain position?
To extract a portion of a string up to a certain position in PHP, you can use the substr() function. This function takes the string to extract from as the first argument, the starting position as the second argument, and the length of the extracted substring as the third argument. To extract a portion of a string up to a certain position, you can calculate the length by subtracting the starting position from the desired end position.
$string = "Hello, World!";
$start_position = 0;
$end_position = 5;
$extracted_string = substr($string, $start_position, $end_position - $start_position);
echo $extracted_string; // Output: Hello