What are the differences between urlencode and rawurlencode in PHP, and when should each be used?
urlencode and rawurlencode are both PHP functions used to encode a string for use in a URL. The main difference between them is how they handle certain characters. urlencode encodes spaces as "+" and rawurlencode encodes spaces as "%20". Generally, urlencode is used for encoding query string parameters, while rawurlencode is used for encoding the entire URL.
// Using urlencode
$url = "https://www.example.com/search?q=" . urlencode("hello world");
// Using rawurlencode
$url = "https://www.example.com/search?q=" . rawurlencode("hello world");