Code Point
September 10, 2010, 07:20:08 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Geshi Sintax Hilighting Mod Installed. Tens of languages available.
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Passing array in query string  (Read 7746 times)
Max Woofer
Jr. Member
*

Karma: 0
Offline Offline

Posts: 2


« on: September 25, 2006, 10:23:03 AM »

I need to pass an array from one page to another in the query string. How can I turn an array into a parseable string?
Logged
Web Xman
Moderator
Jr. Member
*****

Karma: 0
Offline Offline

Posts: 2


« Reply #1 on: September 25, 2006, 11:25:18 AM »

The easiest is to serialize it and then encode it.

Code
<?php
$a = array('x' => '&quot;', '&amp;' => 3);
$a = rawurlencode(serialize($a));
echo '<a href="./getarray.php?a=' . $a . '">Pass array</a>';
?>

The receiving getarray.php page:

Code
<?php
header('Content-Type: text/plain');
$a = unserialize($_GET['a']);
print_r($a);
?>

The header is there only to avoid HTML parsing by the browser in the example. You will not need it in a real program.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!