note 74337 added to function.urlencode
| From: | IanPaulShortchukdocs at hotmail dot com | Date: | Fri, 06 Apr 2007 04:22:31 +0000 |
| Subject: | note 74337 added to function.urlencode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-125133@lists.php.net to get a copy of this message | ||
Uniform Resource Locators (URL) & XHTML compliance
Reference to http://www.rfc-editor.org/rfc/rfc1738.txt
The following is compliant for a redirect (but not for a link in <a>anchor</a> tags):
<?php
$url = "www.some.com/query.php"
foreach ($aQuery as $key => $val){
$aTemp[] = urlencode($key) . '=' . urlencode($val);
}
$url_query_string = join('&', $aTemp);
header("Location: $url . $url_query_string" );
?>
For links the '&' in the join must be an HTML entity to be XHTML compliant.
<?php
$url = "www.some.com/query.php"
foreach ($aQuery as $key => $val){
$aTemp[] = urlencode($key) . '=' . urlencode($val);
}
$url_query_string = '?' . join(htmlspecialchars('&'), $aTemp);
echo '<a href="' . $url . $url_query_string .
'>Compliant</a>' ;
?>
For both examples the $aQuery is an associative array:
<?php
$aQuery = array(
"example_one" => "redirect",
"example_two" => "link"
);
?>
----
Server IP: 194.145.210.3
Probable Submitter: 81.158.78.51
----
Manual Page -- http://www.php.net/manual/en/function.urlencode.php
Edit -- https://master.php.net/note/edit/74337
Del: integrated -- https://master.php.net/note/delete/74337/integrated
Del: useless -- https://master.php.net/note/delete/74337/useless
Del: bad code -- https://master.php.net/note/delete/74337/bad+code
Del: spam -- https://master.php.net/note/delete/74337/spam
Del: non-english -- https://master.php.net/note/delete/74337/non-english
Del: in docs -- https://master.php.net/note/delete/74337/in+docs
Del: other reasons-- https://master.php.net/note/delete/74337
Reject -- https://master.php.net/note/reject/74337
Search -- https://master.php.net/manage/user-notes.php