PHP Developer Question:

How you can protect special characters in Query String?

Tweet Share WhatsApp

Answer:

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 GlobalGuideLine.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>");
?>

Download PHP Developer PDF Read All 57 PHP Developer Questions
Previous QuestionNext Question
Suppose if variable $a is equal to 5 and variable $b is equal to character a, what's the value of $$b?Can you please explain the difference between $message and $$message?