Skip to content

Instantly share code, notes, and snippets.

@erikreagan
Created October 27, 2009 21:28

Revisions

  1. erikreagan revised this gist Oct 27, 2009. 2 changed files with 3 additions and 2 deletions.
    3 changes: 2 additions & 1 deletion tm-serialization-command1.php
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,8 @@
    <?php

    // This command simply prints out the serialized data in a readable printed array format

    // Found on a blog via a google search
    // @see http://top-frog.com/2009/08/28/quickly-unserialize-data-in-textmate/
    $data = unserialize(file_get_contents('php://stdin'));

    print_r($data);
    2 changes: 1 addition & 1 deletion tm-serialization-command2.php
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    <?php

    // This command is the "re-serialization" version of my other gist

    // I needed a way to get my newly edited data back to it's original serialized format so I wrote this

    // First we create an array with each line (with the exception of the first and last)
    $string_to_array = explode("\n",file_get_contents('php://stdin'));
  2. erikreagan revised this gist Oct 27, 2009. 2 changed files with 0 additions and 0 deletions.
  3. erikreagan created this gist Oct 27, 2009.
    23 changes: 23 additions & 0 deletions TextMate-Re-serialization-Commands.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #!/usr/bin/env php
    <?php

    // This command is the "re-serialization" version of my other gist


    // First we create an array with each line (with the exception of the first and last)
    $string_to_array = explode("\n",file_get_contents('php://stdin'));

    // We cycle through the array and turn the data into a usable php array
    foreach ($string_to_array as $line) {
    if(preg_match("/(\s+)\[/", $line))
    {
    $key = preg_replace("/(\s+\[(.*)\].+)/","$2",$line);
    $value = preg_replace("/.+(=> (.*)\n?)/","$2",$line);
    $array_result[$key] = $value;
    }
    }

    // Then we print it back out serialized and ready to be put back wherever it came from
    echo serialize($array_result);

    ?>
    10 changes: 10 additions & 0 deletions TextMate-Unserialization-Commands.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    #!/usr/bin/env php
    <?php

    // This command simply prints out the serialized data in a readable printed array format

    $data = unserialize(file_get_contents('php://stdin'));

    print_r($data);

    ?>