Home > DeveloperSection > Interviews > How To Protect Special Characters in Query String?

Posted on    March-18-2011 12:00 AM

 ASP.Net ASP.Net 
Ratings:
 1 Answer(s)
  1468  View(s)
Rate this:

Sanjay Sharma
Sanjay Sharma

Total Post:42

Points:210
Posted on    March-18-2011 12:00 AM


If you want to include special characters like spaces in the query string, you need to protect them by applying the urlencode() translation function.

The script below shows how to use urlencode():

<?php
print(”<html>”);
print(”<p>Please click the links below”
.” to submit comments about FYICenter.com:</p>”);
$comment = ‘I want to say: “It\’s a good site! :->”‘;
$comment = urlencode($comment);
print(”<p>”
.”<a href=\”processing_forms.php?name=Guest&comment=$comment\”>”
.”It’s an excellent site!</a></p>”);
$comment = ‘This visitor said: “It\’s an average site! :-( ”‘;
$comment = urlencode($comment);
print(”<p>”
.’<a href=”processing_forms.php?’.$comment.’”>’
.”It’s an average site.</a></p>”);
print(”</html>”);
?>


Modified On Apr-04-2016 12:36:54 AM

Don't want to miss updates? Please click the below button!

Follow MindStick