// Encode a string for use in a URL using the urlencode() function
$url = 'https://www.example.com/page.php?name=John Doe';
$encoded_url = urlencode($url);
echo $encoded_url . '<br>';
// Output: 'https%3A%2F%2Fwww.example.com%2Fpage.php%3Fname%3DJohn+Doe'

// Decode a URL encoded with urlencode()
$decoded_url = urldecode($url);
echo $decoded_url;
// Output: 'https://www.example.com/page.php?name=John Doe'
/* Encode a query parameter value using rawurlencode() */
$keyword = 'iPhone & Galaxy/Note=100% #1';
$encoded = rawurlencode($keyword);

echo 'https://example.com/search?query=' . $encoded;
// Output: 'https://example.com/search?query=iPhone%20%26%20Galaxy%2FNote%3D100%25%20%231'

/* Decode the query parameter using rawurldecode() */
$decoded = rawurldecode($encoded);
echo $decoded;
// Output: 'iPhone & Galaxy/Note=100% #1'
// An array to be encoded into a URL-encoded query string
$data = array(
    'name' => 'John Doe',
    'age' => 30,
    'city' => 'New York'
);

// Encode the array into a query string using http_build_query()
$queryString = http_build_query($data);
echo $queryString; // Output: name=John+Doe&age=30&city=New+York'

// Decode the query string using parse_str()
// Store the parsed data as an array in the second argument, $decodedArray
parse_str($queryString, $decodedArray);

print_r($decodedArray); // Output:  Array ( [name] => John Doe [age] => 30 [city] => New York )