Connecting Tech Pros Worldwide Forums | Help | Site Map

How to move arrays from html webpage to webpage?

duzhidian@gmail.com
Guest
 
Posts: n/a
#1: Jan 15 '07
Hello:

There are a couple techniques to move information from different html
web page to web page.
1. URL;
2. Cookie;
3. Form;
4. Session;

All the examples I found are move distinguished variables from page to
page, such as "?weight=20&name='apple'".


I need users choose from the first web page (the arrays will be
generated), then use it in second and third html web pages. How do I
transfer them (arrays) and which way is the best?

For example, if I have two arrays,

$fruit[] = array("apple", "pear", "orange");
and associative array
$myCats["Me"]="Merry";
$myCats["Pi"]="Pippin";
$myCats["He"]="Hergie";

How to do that?

Thanks in advance.

Z. D


Sanders Kaufman
Guest
 
Posts: n/a
#2: Jan 15 '07

re: How to move arrays from html webpage to webpage?


duzhidian@gmail.com wrote:
Quote:
Hello:
>
There are a couple techniques to move information from different html
web page to web page.
1. URL;
2. Cookie;
3. Form;
4. Session;
>
All the examples I found are move distinguished variables from page to
page, such as "?weight=20&name='apple'".
>
>
I need users choose from the first web page (the arrays will be
generated), then use it in second and third html web pages. How do I
transfer them (arrays) and which way is the best?
>
For example, if I have two arrays,
>
$fruit[] = array("apple", "pear", "orange");
and associative array
$myCats["Me"]="Merry";
$myCats["Pi"]="Pippin";
$myCats["He"]="Hergie";
>
How to do that?
>
Thanks in advance.
You could use the "explode" and "compress" array functions in PHP.
Kimmo Laine
Guest
 
Posts: n/a
#3: Jan 15 '07

re: How to move arrays from html webpage to webpage?


<duzhidian@gmail.comwrote in message
news:1168848261.353857.300790@38g2000cwa.googlegro ups.com...
Quote:
Hello:
>
There are a couple techniques to move information from different html
web page to web page.
1. URL;
2. Cookie;
3. Form;
4. Session;
>
All the examples I found are move distinguished variables from page to
page, such as "?weight=20&name='apple'".
Arrays can be used as get parameters as well.
"?apple[0]=foo&apple[1]=bar&apple[jack]=baz" works just fine.


--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
spam@outolempi.net | rot13(xvzzb@bhgbyrzcv.arg)


bill
Guest
 
Posts: n/a
#4: Jan 15 '07

re: How to move arrays from html webpage to webpage?


duzhidian@gmail.com wrote:
Quote:
Hello:
>
There are a couple techniques to move information from different html
web page to web page.
1. URL;
2. Cookie;
3. Form;
4. Session;
>
All the examples I found are move distinguished variables from page to
page, such as "?weight=20&name='apple'".
>
>
I need users choose from the first web page (the arrays will be
generated), then use it in second and third html web pages. How do I
transfer them (arrays) and which way is the best?
>
For example, if I have two arrays,
>
$fruit[] = array("apple", "pear", "orange");
and associative array
$myCats["Me"]="Merry";
$myCats["Pi"]="Pippin";
$myCats["He"]="Hergie";
>
How to do that?
>
Thanks in advance.
>
Z. D
>
A session is the easiest way.
Toby Inkster
Guest
 
Posts: n/a
#5: Jan 15 '07

re: How to move arrays from html webpage to webpage?


Sanders Kaufman wrote:
Quote:
You could use the "explode" and "compress" array functions in PHP.
serialize() and unserialize() would probably be better choices.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Toby Inkster
Guest
 
Posts: n/a
#6: Jan 15 '07

re: How to move arrays from html webpage to webpage?


duzhidian@gmail.com wrote:
Quote:
There are a couple techniques to move information from different html
web page to web page.
1. URL;
2. Cookie;
3. Form;
4. Session;
All of them *could* be used to store and retrieve array information, but
sessions are by far the easiest.

The others are only capable of storing and retrieving strings (not
arrays), so you'd need to use/write functions to do array<=>string
conversion. (serialize() and unserialize() are the the built-in PHP
functions to convert between array and string, and should be used
unless you have an overwhelming reason not to.)

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Sanders Kaufman
Guest
 
Posts: n/a
#7: Jan 15 '07

re: How to move arrays from html webpage to webpage?


Toby Inkster wrote:
Quote:
Sanders Kaufman wrote:
>
Quote:
>You could use the "explode" and "compress" array functions in PHP.
>
serialize() and unserialize() would probably be better choices.

I thought those were the same thing.
What's the difference?
Toby Inkster
Guest
 
Posts: n/a
#8: Jan 16 '07

re: How to move arrays from html webpage to webpage?


Sanders Kaufman wrote:
Quote:
Toby Inkster wrote:
Quote:
>Sanders Kaufman wrote:
>>
Quote:
>>You could use the "explode" and "compress" array functions in PHP.
>>
>serialize() and unserialize() would probably be better choices.
>
I thought those were the same thing.
What's the difference?
Firstly, there's no such function as "compress". I'd assumed you'd meant
"implode" which is the counterpart of "explode".

<?php

$orig = array('foo', 'bar', 'baz');
print "Original:\n"; var_dump($orig);
$imploded = implode(':', $orig);
$serialized = serialize($orig);
print "Imploded is '$imploded'.\n";
print "Serialized is '$serialized'.\n";
$exploded = explode(':', $imploded);
$unserialized = unserialize($serialized);
print "Exploded:\n"; var_dump($exploded);
print "\nUnserialized:\n"; var_dump($unserialized);

print "\n\n----------------------\n\n";

$orig = array('foo'=>12, 'bar'=>24, 'baz'=>18);
print "Original:\n"; var_dump($orig);
$imploded = implode(':', $orig);
$serialized = serialize($orig);
print "Imploded is '$imploded'.\n";
print "Serialized is '$serialized'.\n";
$exploded = explode(':', $imploded);
$unserialized = unserialize($serialized);
print "Exploded:\n"; var_dump($exploded);
print "\nUnserialized:\n"; var_dump($unserialized);

?>

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Sanders Kaufman
Guest
 
Posts: n/a
#9: Jan 16 '07

re: How to move arrays from html webpage to webpage?


Toby Inkster wrote:
Quote:
Sanders Kaufman wrote:
Quote:
Quote:
Quote:
>>>You could use the "explode" and "compress" array functions in PHP.
>>serialize() and unserialize() would probably be better choices.
>I thought those were the same thing.
>What's the difference?
>
Firstly, there's no such function as "compress". I'd assumed you'd meant
"implode" which is the counterpart of "explode".

Yeah - that's what I meant :)


Quote:
>
<?php
>
$orig = array('foo', 'bar', 'baz');
print "Original:\n"; var_dump($orig);
$imploded = implode(':', $orig);
$serialized = serialize($orig);
print "Imploded is '$imploded'.\n";
print "Serialized is '$serialized'.\n";
$exploded = explode(':', $imploded);
$unserialized = unserialize($serialized);
print "Exploded:\n"; var_dump($exploded);
print "\nUnserialized:\n"; var_dump($unserialized);
>
print "\n\n----------------------\n\n";
>
$orig = array('foo'=>12, 'bar'=>24, 'baz'=>18);
print "Original:\n"; var_dump($orig);
$imploded = implode(':', $orig);
$serialized = serialize($orig);
print "Imploded is '$imploded'.\n";
print "Serialized is '$serialized'.\n";
$exploded = explode(':', $imploded);
$unserialized = unserialize($serialized);
print "Exploded:\n"; var_dump($exploded);
print "\nUnserialized:\n"; var_dump($unserialized);
>
?>
>
Kimmo Laine
Guest
 
Posts: n/a
#10: Jan 16 '07

re: How to move arrays from html webpage to webpage?


"Sanders Kaufman" <bucky@kaufman.netwrote in message
news:otSqh.20353$yC5.3398@newssvr27.news.prodigy.n et...
Quote:
Toby Inkster wrote:
Quote:
>Sanders Kaufman wrote:
>>
Quote:
>>You could use the "explode" and "compress" array functions in PHP.
>>
>serialize() and unserialize() would probably be better choices.
>
>
I thought those were the same thing.
What's the difference?

$original = array('foo'=>'bar;zap');
print_r($original);
print_r(unserialize(serialize($original)));
print_r(explode(';', implode(';', $original)));

Differences when using explode/implode:
- keys are lost
- if a string value happens to have the split/glue character, it totally
messes up the array

serialize/unserialize preserves the array structure better. Implode and
explode aren't completely useless, on a special occasion they work just
fine, still serialize/unserialize is more stable solution.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
spam@outolempi.net | rot13(xvzzb@bhgbyrzcv.arg)


Closed Thread