How To Protect Special Characters in Query String?

How To Protect Special Characters in Query String?

View Answers

November 15, 2010 at 1:00 PM

Hi all,

For this purpose you can urlencode() translation function.

Example :

<?php

$string = "This is deepak.";

$url = "my.php?data=" . urlencode($string);
print "<a href=\"$url\">Just Click</a><br>";
if (isset($_REQUEST["data"])) {
   print "URL IS : " . $_SERVER['REQUEST_URI'] . "<br>";
   print "Decoded data is : " . urldecode($_REQUEST["data"]);
}

?>

The output :

Just Click 
URL IS : /my.php?data=This+is+deepak+.
Decoded data is : This is deepak.

Thanks









Related Tutorials/Questions & Answers:
Advertisements