note 111410 added to function.urlencode
| From: | leaksin | Date: | Sun, 17 Feb 2013 21:05:48 +0000 |
| Subject: | note 111410 added to function.urlencode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-193663@lists.php.net to get a copy of this message | ||
"cleaning the URL",Totally and in a nut shell:
1.You must use rawurlencode() for parts that come before "?"
2.Use urlencode for all GET parameters (values that come after each "=")(POST parameters
are automatically encoded).
3.Use htmlspecialchars for HTML tag parameters and HTML text content
<?php
$url_page = 'example/page/url.php';
//page the link will request
$text = 'this is a simple string';
$id = '4334%3434';
$linktext = "<Clickit> & you will see it";
//text of the link, with HTML unfriendly characters
?>
<?php
// this gives you a clean link to use
$url = "http://localhost/";
$url .= rawurlencode($url_page);
$url .= "?text=" . urlencode($text);
$url .= "&id=" . urlencode($id);
// htmlspecialchars escapes any html that
// might do bad things to your html page
?>
<a href="<?php echo htmlspecialchars($url); ?>">
<?php echo htmlspecialchars($linktext); ?>
</a>
----
Server IP: 69.147.83.199
Probable Submitter: 5.201.209.209
----
Manual Page -- http://php.net/manual/en/function.urlencode.php
Edit -- https://master.php.net/note/edit/111410
Del: integrated -- https://master.php.net/note/delete/111410/integrated
Del: useless -- https://master.php.net/note/delete/111410/useless
Del: bad code -- https://master.php.net/note/delete/111410/bad+code
Del: spam -- https://master.php.net/note/delete/111410/spam
Del: non-english -- https://master.php.net/note/delete/111410/non-english
Del: in docs -- https://master.php.net/note/delete/111410/in+docs
Del: other reasons-- https://master.php.net/note/delete/111410
Reject -- https://master.php.net/note/reject/111410
Search -- https://master.php.net/manage/user-notes.php