For the URI query value use urlencode/urldecode; for anything else use rawurlencode/rawurldecode.

To create entire query string use http_build_query()

The difference between urlencode and rawurlencode is that

  • urlencode encodes according to application/x-www-form-urlencoded (space is encoded with +) while
  • rawurlencode encodes according to the plain Percent-Encoding (space is encoded with %20).
Answer from Gumbo on Stack Overflow
๐ŸŒ
PHP
php.net โ€บ manual โ€บ en โ€บ function.urlencode.php
PHP: urlencode - Manual
Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs. It is encoded the same way that the posted data from a WWW form is encoded, that is the same way as in application/x-www-form-urlencoded media type.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ php โ€บ php-urlencode-function
PHP urlencode() Function - GeeksforGeeks
July 11, 2025 - This function returns a string consisting of all non-alphanumeric characters exceptโ€”_. It is replaced by the percent (%) sign, followed by two hex digits and spaces encoded as plus (+) signs.
๐ŸŒ
W3Schools
w3schools.com โ€บ tags โ€บ ref_urlencode.ASP
HTML URL Encoding Reference
If you click the "Submit" button below, the browser will URL encode the input before it is sent to the server. A page at the server will display the received input. Try some other input and click Submit again. In JavaScript, PHP, and ASP there are functions that can be used to URL encode a string.
๐ŸŒ
MojoAuth
mojoauth.com โ€บ escaping โ€บ url-escaping-in-php
URL Escaping in PHP | Escaping Methods in Programming Languages
This page will walk you through the essentials of URL escaping, explaining key concepts like encoding special characters, preventing issues with query strings, and improving the security of your web applications. By the end, you'll have a solid grasp of PHP functions like urlencode() and rawurlencode(), empowering you to handle URLs with confidence in your PHP projects.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ php urlencode() function
PHP urlencode() Function - Scaler Topics
March 20, 2024 - The urlencode() function takes ... can be safely used as part of a URL without causing issues or misinterpretations. ... The urlencode() function in PHP returns a URL-encoded string....
Find elsewhere
๐ŸŒ
Functions-Online
functions-online.com โ€บ urlencode.html
test urlencode online - PHP URL functions - functions-online
Test and run urlencode online in your browser. This function is convenient when encoding a string to be used in a query part of a URL, as a conveni
๐ŸŒ
URL Encode
urlencoder.org
URL Encode and Decode - Online
Encode to URL-encoded format or decode from it with various advanced options. Our site has an easy to use online tool to convert your data.
๐ŸŒ
Temboo
temboo.com โ€บ php โ€บ url-encode
How to Encode a URL in PHP
3Go to the Utilities > Encoding > URLEncode Choreo page. Select PHP from the drop down menu at the top of the page.
๐ŸŒ
Gyrocode
gyrocode.com โ€บ home โ€บ web development โ€บ php: urlencode() vs. rawurlencode()
PHP: urlencode() vs. rawurlencode() | Gyrocode.com
March 12, 2018 - Difference between urlencode() and rawurlencode() PHP functions is not explained clearly in the official documentation. A few times I found myself looking it up online and decided to document it for future reference. The difference between these two PHP functions is in their return values. ... Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded ...
๐ŸŒ
URL Encode
urlencoder.org โ€บ enc โ€บ php's
URL Encoding of "php's" - Online
Encode php's to URL-encoded format with various advanced options. Our site has an easy to use online tool to convert your data.
๐ŸŒ
Codepath
guides.codepath.org โ€บ websecurity โ€บ PHP-Encoding-for-URLs
PHP Encoding for URLs | Cybersecurity | CodePath Guides
Encoding for a URL means converting characters to a โ€œ%โ€ followed by two hexadecimal digits. Hexadecimal: Normal numbers range from 0-9. Hexadecimal numbers include 0-9 but also add letters A-F as โ€œdigitsโ€. Each digit has 16 possibilities instead of 10.
๐ŸŒ
Reintech
reintech.io โ€บ blog โ€บ practical-guide-php-urlencode-urldecode-functions
A Practical Guide to PHP's `urlencode()` and `urldecode()` Functions
April 14, 2023 - Learn how to use PHP's urlencode() and urldecode() functions effectively in your web applications, ensuring secure and user-friendly URLs.
๐ŸŒ
Envato Tuts+
code.tutsplus.com โ€บ home โ€บ cloud & hosting โ€บ web servers
Using PHP urlencode and urldecode | Envato Tuts+
August 21, 2021 - The server at example.com will ... two different functions in PHP for encoding strings in URLs. These are called urlencode() and rawurlencode()....
๐ŸŒ
Urlencoder
urlencoder.net โ€บ php-urlencode
PHP urlencode() - URL Encode
Returns a string in which all non-alphanumeric characters except dot (.), dash (-), underscore (_) have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs. <?php $str = 'url encoder'; echo "http://example.com/?param=" .