$var=" data 1 & data 2, data 1 + data 2 = data '3. The number is #123 which is 10% of total";
echo $var;
After sending like this we won't receive the same data and it will be truncated from & char onwards. Let us create two PHP pages and to pass one string data from one to other.
<?php
$var=" data 1 & data 2, data 1 + data 2 = data '3. The number is #123 which is 10% of total";
echo $var."<br>";
$var2=urlencode($var);
echo "<br>
<a href='demo-urldecode.php?var=$var'> This link does not use urlencode and post data as it is</a><br>";
echo "<br>
<a href='demo-urldecode.php?var=$var2'> This link does use urlencode and then post data</a><br>";
?>
<?php
echo " <br><b>from url without decoding we get :</b> $_GET[var]<br>";
echo " <br><b>from url after decoding we get :</b> ".urldecode($_GET['var'])."<br>";
echo " <br><b>from url after decoding we get :</b> ".urldecode($_GET['var'])."<br>";
?>
shabbir | 28-09-2016 |
how to remove <a href='demo-urldecode.php?var=$var'> This link does not use urlencode and post data as it is</a><br>"; .php from url when passing value |
smo1234 | 02-10-2016 |
Yes , to show the difference two links are shown, first one is without urlencode and second one is with encode. You can send data without encoding also. If you are sure about the data. For example if you are sending a numeric data like student id then no need to urlencode the data. |