---
title: "How To Protect Special Characters in Query String?"  
description: "How To Protect Special Characters in Query String?"  
author: "Anonymous User"  
published: 2011-03-18  
updated: 2020-09-23  
canonical: https://www.mindstick.com/interview/479/how-to-protect-special-characters-in-query-string  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 1 minute  

---

# How To Protect Special Characters in Query String?

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():**\

```
<?phpprint(”<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>”);?>
```

\

## Answers

### Answer by Anonymous User

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():**\

```
<?phpprint(”<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>”);?>
```

\


---

Original Source: https://www.mindstick.com/interview/479/how-to-protect-special-characters-in-query-string

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
