You are reading the article How Does Urlencode Work In Php With Examples? updated in September 2023 on the website Chivangcangda.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested October 2023 How Does Urlencode Work In Php With Examples?
Introduction to PHP urlencodeWeb development, programming languages, Software testing & others
Syntax urlencode($strURL);urldecode($strURL);
As we can even the decode URL function have the same parameter. But in the parameter, it will be an encoded string or URL. So if we will pass the actual string, not the decoded one, then the output could be different than the actual string.
How does urlencode work in PHP?The URL encoding comes into existence when we need to pass various types of parameters with some value from one place to another. This is one of the required things so that we can get the actual value accurately at the destination page. We can only get the URL encoded value back to the actual value after applying the urldecode() function. The syntax and the semantics of the urldecode() will remain the same as we can see in the urlendode(). There are various in-built functions to do this job in the PHP language, but urlencode() is one of the most widely used.
urldecode() – for decoding back to the actual string
Examples of using urlencodeDifferent examples are mentioned below:
Example #1A simple of using the urlencode() on various URLs.
Code:
<?phpOutput:
Example #2Let’s try to decode the same URLs as mentioned above to get the same in the actual form. In PHP the for every encoding, there is decoding in general.
Code:
<?phpOutput:
Encoding is all about putting something into the coded form that could be more difficult to read or understand comparatively. It is not to just play with encoding and decoding; this is one of the basic needs in any programming language. When we send the + sign in the URL, it gets changes to some other value, and we cannot access this as it is in all cases.
Example #3The encode is all about replacing some characters with other ones. In general, the urlencode() returns a string in which we can see that all the non-alphanumeric characters except -, . etc. have been replaced. According to the characters, these replacements will be done with a percent (%) sign followed by some hex digits. So let’s have a close look upon the same using an example.
Code:
<?php $string = 'This is a very hot day today in this rainy season - 2023.'; $pathModified = urlencode($string);Output:
Dot (-) – As per the rule, there is no change or replacement.
Example #4Let’s see another example of urencode() with some special character in the string.
Code:
<?php $string = 'Hellö _ Wörld'; $pathModified = urlencode($string); echo $pathModified;In the output of the above program, we can see that special characters have been replaced.
Example #5Let’s see an example of urdecode() with some special character in the string.
Code:
<?php $Destring = 'Hell%C3%B6+W%C3%B6rld'; $pathModified = urldecode($Destring);Output:
In the output of the above program, we can see that the encoded string is getting into the actual string (as in the previous program).
ConclusionThe function urlencode() can be used to decode a string or any parameterized URLs. PHP also has a built-in function the decode back the original string named urldecode(). The urlencode() and the urldecode() can be used in pairs to get the job done; Both of these PHP functions are complementary to each other. PHP also has various other coding and decoding string functions we can move ahead with, but these two are one of the most popular and most widely used functions.
Recommended ArticlesThis is a guide to PHP urlencode. Here we discuss the introduction, syntax, and working of urlencode in PHP along with different examples and code implementation. You may also have a look at the following articles to learn more –
You're reading How Does Urlencode Work In Php With Examples?
Update the detailed information about How Does Urlencode Work In Php With Examples? on the Chivangcangda.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!