How can the urlencode function be used to format user input for GET variables in PHP?
When passing user input as GET variables in PHP, it is important to properly format the input to ensure it is safe and correctly interpreted by the server. One way to do this is by using the `urlencode()` function, which encodes the user input in a way that is suitable for use in URLs. This helps prevent any special characters or spaces in the input from causing issues when passed as GET variables.
$user_input = $_GET['user_input']; // Assuming user input is passed as a GET variable
$encoded_input = urlencode($user_input); // Encode the user input for use in URLs
// Now you can safely use $encoded_input in your URL
echo "http://example.com/?input=" . $encoded_input;