passing Multidimensional array thru the URL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jack

    passing Multidimensional array thru the URL

    Hi All,

    I have an issue with an array that I would to pass to a second php
    script; please note that I cannot use session.
    I have been looking at the functions : rawurlencode / rawurldecode
    urlencode / urldecode
    but it does not seems to work for my variable

    here is an example of variable
    <?
    $x=0;
    $data[$x][title]="My title";
    $data[$x][label]=array("label1" ,"label2","labe l3");
    $data[$x][data]=array(100,150, 145);

    ?>

    How can I pass this variable thru an URL ?

    FYI, the need is to generate a graph with JpGraph
    (http://www.aditus.nu/jpgraph/)

    I would appreciate any feedback
    Please advise,
    Thanks
    Jack.
  • ZeldorBlat

    #2
    Re: passing Multidimensiona l array thru the URL

    Check out serialize() and unserialize() :

    Generates a storable representation of a value

    Creates a PHP value from a stored representation


    They basically let you take any type of variable (objects, arrays,
    etc....but not resource handles) and turn them into a string. So, on
    your first page you might have:

    $url_data = urlencode(seria lize($data));

    and on the second page:

    $data = unserialize(url decode($url_dat a));

    Comment

    • Jack

      #3
      Re: passing Multidimensiona l array thru the URL

      ZeldorBlat wrote:[color=blue]
      > Check out serialize() and unserialize() :
      >
      > http://www.php.net/serialize
      > http://www.php.net/unserialize
      >
      > They basically let you take any type of variable (objects, arrays,
      > etc....but not resource handles) and turn them into a string. So, on
      > your first page you might have:
      >
      > $url_data = urlencode(seria lize($data));
      >
      > and on the second page:
      >
      > $data = unserialize(url decode($url_dat a));
      >[/color]
      Arf !
      Stupid me !!!
      I did use the same code, but on the second page I did not reverse the
      code such as
      urldecode(unser ialize($url_dat a));
      instead of unserialize(url decode($url_dat a));

      I tested and it worked.

      Thank much you for opening my eyes
      :-D

      Comment

      • R. Rajesh Jeba Anbiah

        #4
        Re: passing Multidimensiona l array thru the URL

        Jack wrote:[color=blue]
        > I have an issue with an array that I would to pass to a second php
        > script; please note that I cannot use session.
        > I have been looking at the functions : rawurlencode / rawurldecode
        > urlencode / urldecode
        > but it does not seems to work for my variable
        >
        > here is an example of variable
        > <?
        > $x=0;
        > $data[$x][title]="My title";
        > $data[$x][label]=array("label1" ,"label2","labe l3");
        > $data[$x][data]=array(100,150, 145);
        >
        > ?>
        >
        > How can I pass this variable thru an URL ?[/color]
        <snip>

        http://www.example.com/test.php?data[0][title]=My%20title&dat a[0][label][]=label1&data[0][label][]=label2&data[0][label][]=label3&data[0][data][]=100&data[0][data][]=150&data[0][data][]=145

        --
        <?php echo 'Just another PHP saint'; ?>
        Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com

        Comment

        Working...