What is the function rawurlencode() used for in PHP when dealing with URL variables?

When dealing with URL variables in PHP, it is important to properly encode special characters to ensure the data is transmitted correctly. The rawurlencode() function is used to encode a string by replacing special characters with their hexadecimal representation. This helps prevent errors or data corruption when passing variables in URLs.

// Example of using rawurlencode() to encode a URL variable
$variable = "Hello World!";
$encoded_variable = rawurlencode($variable);

// Output the encoded variable
echo "Encoded variable: " . $encoded_variable;