SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 27 of 27
  1. #26
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,810
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    If you want an associative array after decoding the json_encode output, then yes. Otherwise, you end up with an object and have to access your values like so: $decodedArray->plaintext and $decodedArray->filename versus, when using true in the optional parameter, you can use it as $decodedArray['plaintext'] and $decodedArray['filename']

  2. #27
    SitePoint Zealot
    Join Date
    Jun 2010
    Location
    Arizona
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Instead of using json_encode()/json_decode(), use serialize()/unserialize(). The latter allows you to do things like transfer PHP objects intact across hosts while JSON is more limited. If you are transferring data from a database, I recommend doing:

    PHP Code:
    echo base64_encode(serialize($row)) . "\n"
    On the source and this:

    PHP Code:
    $lines explode("\n"file_get_contents("sourceurlhere"));
    foreach (
    $lines as $line)
    {
      
    $row unserialize(base64_decode(trim($line)));
    ...

    For the destination. That's the fastest, easiest way to get data to cross from one PHP host to another on a temporary basis (e.g. a data migration export/import script set for a redesigned web app). You wouldn't want to do this sort of thing for anything other than a quick-n-dirty script that will be used just once or twice - otherwise you'll create a maintenance nightmare in short order.
    Thomas Hruska

    Single Sign-On Server/Client - The PHP login system that rocks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •