How can the trim function be used to remove whitespace when extracting values from a string in PHP?

When extracting values from a string in PHP, the trim function can be used to remove any leading or trailing whitespace that may be present. This is useful for ensuring that the extracted values are clean and do not contain any unwanted spaces. To use the trim function, simply pass the string to be trimmed as an argument, and it will return the string with leading and trailing whitespace removed.

// Example of using trim to remove whitespace when extracting values from a string
$string = "   Hello, World!   ";
$trimmedString = trim($string);

echo $trimmedString; // Output: "Hello, World!"