PHP URL encoding/decoding
P粉512363233
2023-08-14 13:16:12
<p>I used the accepted solution in this question to encrypt the id, for example in <strong>/index.php?id=3</strong>. The problem is that I cannot send the encrypted value as a url like <strong>/index.php?id=dsf13f3343f23/23=</strong>. Because sometimes there are strange characters in the URL, for example, pay attention to the <code>=</code> symbol</p> at the end
Use PHP's
urlencode()
function to encode the value before putting it in the URL.This function converts "strange" characters, such as
=
, into a format that is safe to put in the URL. You can use it like this:Strange characters in the value passed in the URL should be escaped using urlencode()
.
For example, the following code snippet:
will give:If you want to build a query string with multiple parameters, check out the
For example:http_build_query()
function.