Is there any clean and easy way to urlencode()
an arbitrary string but leave slashes (/
) alone?
Why do we need to encode? URLs can only have certain characters from the standard 128 character ASCII set. Reserved characters that do not belong to this set must be encoded. This means that we need to encode these characters when passing into a URL.
Encodes text and merge field values for use in URLs by replacing characters that are illegal in URLs, such as blank spaces, with the code that represent those characters as defined in RFC 3986, Uniform Resource Identifier (URI): Generic Syntax.
urlencode () is the function that can be used conveniently to encode a string before using in a query part of a URL. This is a convenient way for passing variables to the next page. urldecode() is the function that is used to decode the encoded string.
/
urlencode()
each part/
You can do like this:
$url = "http://www.google.com/myprofile/id/1001";
$encoded_url = urlencode($url);
$after_encoded_url = str_replace("%2F", "/", $url);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With