$string = "Hello, world!"; $urlEncoded = rawurlencode($string); echo $urlEncoded; // Output: Hello%2C%20world%21
$rawData = array( "name" => "John Doe", "age" => 35, "email" => "john.doe@example.com" ); $urlEncodedData = http_build_query($rawData); echo $urlEncodedData; // Output: name=John+Doe&age=35&email=john.doe%40example.comIn this example, we have a raw data array containing some personal information. We want to convert this data to URL encoded format so that it can be transmitted in a URL or form submission. We use the `http_build_query()` function, which converts an array into a URL encoded query string. Package/Library: The `rawurlencode()` function is a built-in function in PHP, while the `http_build_query()` function is part of the PHP Standard Library. No external package or library is required for these functions.