note 74337 deleted from function.urlencode by philip

From: Date: Fri, 06 Apr 2007 08:03:54 +0000
Subject: note 74337 deleted from function.urlencode by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-125137@lists.php.net to get a copy of this message
Note Submitter: Ian Paul Short chukdocs at hotmail dot com ---- 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" ); ?>

« previous php.notes (#125137) next »