What function can be used to remove leading and trailing whitespace from a string in PHP?
Leading and trailing whitespace in a string can be removed in PHP using the `trim()` function. This function takes a string as input and returns a new string with any leading or trailing whitespace removed. This is useful for cleaning up user input or data retrieved from external sources before further processing.
$string = " Hello, World! ";
$trimmedString = trim($string);
echo $trimmedString; // Output: "Hello, World!"
Related questions
-
isset $_GET variables potential errors
-
array_merge array_values array_combine
-
cookies PHP security