Avatar ·

What is the difference between urlencode and rawurlencode in PHP and when to use which?

Hello everyone! I'm a beginner PHP developer, and I'm confused about two functions: `urlencode()` and `rawurlencode()`. I know that both are used for URL encoding, but I can't understand the fundamental difference between them and which one is more correct to use. For example, I need to pass a string with Cyrillic characters and spaces in a URL: ```php $string = "Привет мир!"; echo urlencode($string); // %D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82+%D0%BC%D0%B8%D1%80%21 echo rawurlencode($string); // %D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82%20%D0%BC%D0%B8%D1%80%21 ``` I noticed that `urlencode` replaces spaces with `+`, while `rawurlencode` replaces them with `%20`. But when I read the RFC 3986 documentation, it says that spaces should be encoded as `%20`. So why does the `urlencode` function exist, which enco