Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How To Protect Special Characters in Query String
How To Protect Special Characters in Query String? - PHP Script Tips - Processing Web Forms
✍: FYIcenter.com
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>");
?>
If you copy this script as submit_comments.php to your Web server, and click the first link, you will get:
query_string = name=Guest&comment=
I+want+to+say%3A+%22It%27s+a+good+site%21+%3A-%3E%22
Number of values: 2
name = Guest
comment = I want to say: "It's a good site! :->"
If you click the second link, you will get:
query_string
= This+visitor+said%3A+%22It%27s+an+average+site%21+%3A-%28%22
Number of values: 1
This_visitor_said:_\"It\'s_an_average_site!_:-(\" =
Now you know that urlencode() all special characters into HEX numbers. To translate them back, you need to apply urldecode().
2007-04-22, 5744👍, 0💬
Popular Posts:
How is normally a project management plan document organized ? PMP document forms the bible of a pro...
What is difference between Association, Aggregation and Inheritance relationships? In object oriente...
What is the difference between include directive & jsp:include action? Difference between includ...
Which are the various programming approaches for WCF?
What is Concern in AOP? gA concern is a particular goal, concept, or area of interesth There are m...