Dave3765 Posted October 31, 2007 Share Posted October 31, 2007 Hey Guys, Grrrrrrrrrrrrrrrrrrrrrrr! I have a text file called tester2.txt that looks like this: array(20) { [0]=> array(4) { ["row0"]=> string(14) "Row 0 column 0" ["row1"]=> string(14) "Row 0 column 1" } [1]=> array(4) { ["row0"]=> string(14) "Row 1 column 0" ["row1"]=> string(14) "Row 1 column 1" } [2]=> array(4) { ["row0"]=> string(14) "Row 2 column 0" ["row1"]=> string(14) "Row 2 column 1" } [3]=> array(4) { ["row0"]=> string(14) "Row 3 column 0" ["row1"]=> string(14) "Row 3 column 1" } [4]=> array(4) { ["row0"]=> string(14) "Row 4 column 0" ["row1"]=> string(14) "Row 4 column 1" } [5]=> array(4) { ["row0"]=> string(14) "Row 5 column 0" ["row1"]=> string(14) "Row 5 column 1" } [6]=> array(4) { ["row0"]=> string(14) "Row 6 column 0" ["row1"]=> string(14) "Row 6 column 1" } [7]=> array(4) { ["row0"]=> string(14) "Row 7 column 0" ["row1"]=> string(14) "Row 7 column 1" } [8]=> array(4) { ["row0"]=> string(14) "Row 8 column 0" ["row1"]=> string(14) "Row 8 column 1" } [9]=> array(4) { ["row0"]=> string(14) "Row 9 column 0" ["row1"]=> string(14) "Row 9 column 1" } [10]=> array(4) { ["row0"]=> string(15) "Row 10 column 0" ["row1"]=> string(15) "Row 10 column 1" } } I need to open the text file, serialize the values and save it - here is how I am trying to do that (but it won't work! ): <?php $data = file_get_contents("./tester2.txt"); $open = fopen("./tester2.txt", 'w'); fwrite($open, serialize($data)); fclose($open); ?> All it does it serialize the whole text file as 1 item, but I need to serialize the individual values. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/75534-solved-how-do-i-serialize-an-array-in-a-text-file/ Share on other sites More sharing options...
wildteen88 Posted October 31, 2007 Share Posted October 31, 2007 What do you mean by the individual values? serialize() will serialize the whole contents of tester2.txt as it'll see it as a string (text) and not an array. How was tester2.txt populated in the first place? Quote Link to comment https://forums.phpfreaks.com/topic/75534-solved-how-do-i-serialize-an-array-in-a-text-file/#findComment-382143 Share on other sites More sharing options...
Dave3765 Posted October 31, 2007 Author Share Posted October 31, 2007 It was the flat database file that I got as part of a script. It originally looked like this: a:20:{i:0;a:4:{s:4:"row0";s:14:"Row 0 column 0";s:4:"row1";s:14:"Row 0 column 1";s:4:"row2";s:14:"Row 0 column 2";s:4:"row3";s:14:"Row 0 column 3";}i:1;a:4:{s:4:"row0";s:14:"Row 1 column 0";s:4:"row1";s:14:"Row 1 column 1";s:4:"row2";s:14:"Row 1 column 2";s:4:"row3";s:14:"Row 1 column 3";}i:2;a:4:{s:4:"row0";s:14:"Row 2 column 0";s:4:"row1";s:14:"Row 2 column 1";s:4:"row2";s:14:"Row 2 column 2";s:4:"row3";s:14:"Row 2 column 3";}i:3;a:4:{s:4:"row0";s:14:"Row 3 column 0";s:4:"row1";s:14:"Row 3 column 1";s:4:"row2";s:14:"Row 3 column 2";s:4:"row3";s:14:"Row 3 column 3";}i:4;a:4:{s:4:"row0";s:14:"Row 4 column 0";s:4:"row1";s:14:"Row 4 column 1";s:4:"row2";s:14:"Row 4 column 2";s:4:"row3";s:14:"Row 4 column 3";}i:5;a:4:{s:4:"row0";s:14:"Row 5 column 0";s:4:"row1";s:14:"Row 5 column 1";s:4:"row2";s:14:"Row 5 column 2";s:4:"row3";s:14:"Row 5 column 3";}i:6;a:4:{s:4:"row0";s:14:"Row 6 column 0";s:4:"row1";s:14:"Row 6 column 1";s:4:"row2";s:14:"Row 6 column 2";s:4:"row3";s:14:"Row 6 column 3";}i:7;a:4:{s:4:"row0";s:14:"Row 7 column 0";s:4:"row1";s:14:"Row 7 column 1";s:4:"row2";s:14:"Row 7 column 2";s:4:"row3";s:14:"Row 7 column 3";}i:8;a:4:{s:4:"row0";s:14:"Row 8 column 0";s:4:"row1";s:14:"Row 8 column 1";s:4:"row2";s:14:"Row 8 column 2";s:4:"row3";s:14:"Row 8 column 3";}i:9;a:4:{s:4:"row0";s:14:"Row 9 column 0";s:4:"row1";s:14:"Row 9 column 1";s:4:"row2";s:14:"Row 9 column 2";s:4:"row3";s:14:"Row 9 column 3";}i:10;a:4:{s:4:"row0";s:15:"Row 10 column 0";s:4:"row1";s:15:"Row 10 column 1";s:4:"row2";s:15:"Row 10 column 2";s:4:"row3";s:15:"Row 10 column 3";}i:11;a:4:{s:4:"row0";s:15:"Row 11 column 0";s:4:"row1";s:15:"Row 11 column 1";s:4:"row2";s:15:"Row 11 column 2";s:4:"row3";s:15:"Row 11 column 3";}i:12;a:4:{s:4:"row0";s:15:"Row 12 column 0";s:4:"row1";s:15:"Row 12 column 1";s:4:"row2";s:15:"Row 12 column 2";s:4:"row3";s:15:"Row 12 column 3";}i:13;a:4:{s:4:"row0";s:15:"Row 13 column 0";s:4:"row1";s:15:"Row 13 column 1";s:4:"row2";s:15:"Row 13 column 2";s:4:"row3";s:15:"Row 13 column 3";}i:14;a:4:{s:4:"row0";s:15:"Row 14 column 0";s:4:"row1";s:15:"Row 14 column 1";s:4:"row2";s:15:"Row 14 column 2";s:4:"row3";s:15:"Row 14 column 3";}i:15;a:4:{s:4:"row0";s:15:"Row 15 column 0";s:4:"row1";s:15:"Row 15 column 1";s:4:"row2";s:15:"Row 15 column 2";s:4:"row3";s:15:"Row 15 column 3";}i:16;a:4:{s:4:"row0";s:15:"Row 16 column 0";s:4:"row1";s:15:"Row 16 column 1";s:4:"row2";s:15:"Row 16 column 2";s:4:"row3";s:15:"Row 16 column 3";}i:17;a:4:{s:4:"row0";s:15:"Row 17 column 0";s:4:"row1";s:15:"Row 17 column 1";s:4:"row2";s:15:"Row 17 column 2";s:4:"row3";s:15:"Row 17 column 3";}i:18;a:4:{s:4:"row0";s:15:"Row 18 column 0";s:4:"row1";s:15:"Row 18 column 1";s:4:"row2";s:15:"Row 18 column 2";s:4:"row3";s:15:"Row 18 column 3";}i:19;a:4:{s:4:"row0";s:15:"Row 19 column 0";s:4:"row1";s:15:"Row 19 column 1";s:4:"row2";s:15:"Row 19 column 2";s:4:"row3";s:15:"Row 19 column 3";}} And I used this site to unserialize it - I am trying to change the values and then re-serialize it. If you are interested the script is an ajax html table editor. Quote Link to comment https://forums.phpfreaks.com/topic/75534-solved-how-do-i-serialize-an-array-in-a-text-file/#findComment-382149 Share on other sites More sharing options...
wildteen88 Posted October 31, 2007 Share Posted October 31, 2007 Use PHP's built in unserialize function on that string. Eg: <?php $data = 'a:20:{i:0;a:4:{s:4:"row0";s:14:"Row 0 column 0";s:4:"row1";s:14:"Row 0 column 1";s:4:"row2";s:14:"Row 0 column 2";s:4:"row3";s:14:"Row 0 column 3";}i:1;a:4:{s:4:"row0";s:14:"Row 1 column 0";s:4:"row1";s:14:"Row 1 column 1";s:4:"row2";s:14:"Row 1 column 2";s:4:"row3";s:14:"Row 1 column 3";}i:2;a:4:{s:4:"row0";s:14:"Row 2 column 0";s:4:"row1";s:14:"Row 2 column 1";s:4:"row2";s:14:"Row 2 column 2";s:4:"row3";s:14:"Row 2 column 3";}i:3;a:4:{s:4:"row0";s:14:"Row 3 column 0";s:4:"row1";s:14:"Row 3 column 1";s:4:"row2";s:14:"Row 3 column 2";s:4:"row3";s:14:"Row 3 column 3";}i:4;a:4:{s:4:"row0";s:14:"Row 4 column 0";s:4:"row1";s:14:"Row 4 column 1";s:4:"row2";s:14:"Row 4 column 2";s:4:"row3";s:14:"Row 4 column 3";}i:5;a:4:{s:4:"row0";s:14:"Row 5 column 0";s:4:"row1";s:14:"Row 5 column 1";s:4:"row2";s:14:"Row 5 column 2";s:4:"row3";s:14:"Row 5 column 3";}i:6;a:4:{s:4:"row0";s:14:"Row 6 column 0";s:4:"row1";s:14:"Row 6 column 1";s:4:"row2";s:14:"Row 6 column 2";s:4:"row3";s:14:"Row 6 column 3";}i:7;a:4:{s:4:"row0";s:14:"Row 7 column 0";s:4:"row1";s:14:"Row 7 column 1";s:4:"row2";s:14:"Row 7 column 2";s:4:"row3";s:14:"Row 7 column 3";}i:8;a:4:{s:4:"row0";s:14:"Row 8 column 0";s:4:"row1";s:14:"Row 8 column 1";s:4:"row2";s:14:"Row 8 column 2";s:4:"row3";s:14:"Row 8 column 3";}i:9;a:4:{s:4:"row0";s:14:"Row 9 column 0";s:4:"row1";s:14:"Row 9 column 1";s:4:"row2";s:14:"Row 9 column 2";s:4:"row3";s:14:"Row 9 column 3";}i:10;a:4:{s:4:"row0";s:15:"Row 10 column 0";s:4:"row1";s:15:"Row 10 column 1";s:4:"row2";s:15:"Row 10 column 2";s:4:"row3";s:15:"Row 10 column 3";}i:11;a:4:{s:4:"row0";s:15:"Row 11 column 0";s:4:"row1";s:15:"Row 11 column 1";s:4:"row2";s:15:"Row 11 column 2";s:4:"row3";s:15:"Row 11 column 3";}i:12;a:4:{s:4:"row0";s:15:"Row 12 column 0";s:4:"row1";s:15:"Row 12 column 1";s:4:"row2";s:15:"Row 12 column 2";s:4:"row3";s:15:"Row 12 column 3";}i:13;a:4:{s:4:"row0";s:15:"Row 13 column 0";s:4:"row1";s:15:"Row 13 column 1";s:4:"row2";s:15:"Row 13 column 2";s:4:"row3";s:15:"Row 13 column 3";}i:14;a:4:{s:4:"row0";s:15:"Row 14 column 0";s:4:"row1";s:15:"Row 14 column 1";s:4:"row2";s:15:"Row 14 column 2";s:4:"row3";s:15:"Row 14 column 3";}i:15;a:4:{s:4:"row0";s:15:"Row 15 column 0";s:4:"row1";s:15:"Row 15 column 1";s:4:"row2";s:15:"Row 15 column 2";s:4:"row3";s:15:"Row 15 column 3";}i:16;a:4:{s:4:"row0";s:15:"Row 16 column 0";s:4:"row1";s:15:"Row 16 column 1";s:4:"row2";s:15:"Row 16 column 2";s:4:"row3";s:15:"Row 16 column 3";}i:17;a:4:{s:4:"row0";s:15:"Row 17 column 0";s:4:"row1";s:15:"Row 17 column 1";s:4:"row2";s:15:"Row 17 column 2";s:4:"row3";s:15:"Row 17 column 3";}i:18;a:4:{s:4:"row0";s:15:"Row 18 column 0";s:4:"row1";s:15:"Row 18 column 1";s:4:"row2";s:15:"Row 18 column 2";s:4:"row3";s:15:"Row 18 column 3";}i:19;a:4:{s:4:"row0";s:15:"Row 19 column 0";s:4:"row1";s:15:"Row 19 column 1";s:4:"row2";s:15:"Row 19 column 2";s:4:"row3";s:15:"Row 19 column 3";}}'; $data_array = unserialize($data); echo '<pre>' . print_r($data_array, true) . '</pre>'; ?> You can now modify the array's values how you want them. Once done you can re-serialize with serialize Quote Link to comment https://forums.phpfreaks.com/topic/75534-solved-how-do-i-serialize-an-array-in-a-text-file/#findComment-382154 Share on other sites More sharing options...
Dave3765 Posted October 31, 2007 Author Share Posted October 31, 2007 How would I 're-serialize with serialize'? When I try and do it I just get this: s:1243:"Array ( [0] => Array ( [row0] => Row 0 column 0 [row1] => Row 0 column 1 ) [1] => Array ( [row0] => Row 1 column 0 [row1] => Row 1 column 1 ) [2] => Array ( [row0] => Row 2 column 0 [row1] => Row 2 column 1 ) [3] => Array ( [row0] => Row 3 column 0 [row1] => Row 3 column 1 ) [4] => Array ( [row0] => Row 4 column 0 [row1] => Row 4 column 1 ) [5] => Array ( [row0] => Row 5 column 0 [row1] => Row 5 column 1 ) [6] => Array ( [row0] => Row 6 column 0 [row1] => Row 6 column 1 ) [7] => Array ( [row0] => Row 7 column 0 [row1] => Row 7 column 1 ) [8] => Array ( [row0] => Row 8 column 0 [row1] => Row 8 column 1 ) [9] => Array ( [row0] => Row 9 column 0 [row1] => Row 9 column 1 ) [10] => Array ( [row0] => Row 10 column 0 [row1] => Row 10 column 1 ) )"; You see it's just serializing the whole thing. Quote Link to comment https://forums.phpfreaks.com/topic/75534-solved-how-do-i-serialize-an-array-in-a-text-file/#findComment-382174 Share on other sites More sharing options...
wildteen88 Posted October 31, 2007 Share Posted October 31, 2007 You use serialize() on the $data_array variable. You don't write the contents of the variable to a file then serialize the contents of that file. If you do that then the data is no longer an array and is considered a string! What are you trying to do to the original serialized array. Quote Link to comment https://forums.phpfreaks.com/topic/75534-solved-how-do-i-serialize-an-array-in-a-text-file/#findComment-382188 Share on other sites More sharing options...
Dave3765 Posted October 31, 2007 Author Share Posted October 31, 2007 I am trying to get the original text file: a:20:{i:0;a:4:{s:4:"row0";s:14:"Row 0 column 0";s:4:"row1";s:14:"Row 0 column 1";s:4:"row2";s:14:"Row 0 column 2";s:4:"row3";s:14:"Row 0 column 3";}i:1;a:4:{s:4:"row0";s:14:"Row 1 column 0";s:4:"row1";s:14:"Row 1 column 1";s:4:"row2";s:14:"Row 1 column 2";s:4:"row3";s:14:"Row 1 column 3";}i:2;a:4:{s:4:"row0";s:14:"Row 2 column 0";s:4:"row1";s:14:"Row 2 column 1";s:4:"row2";s:14:"Row 2 column 2";s:4:"row3";s:14:"Row 2 column 3";}i:3;a:4:{s:4:"row0";s:14:"Row 3 column 0";s:4:"row1";s:14:"Row 3 column 1";s:4:"row2";s:14:"Row 3 column 2";s:4:"row3";s:14:"Row 3 column 3";}i:4;a:4:{s:4:"row0";s:14:"Row 4 column 0";s:4:"row1";s:14:"Row 4 column 1";s:4:"row2";s:14:"Row 4 column 2";s:4:"row3";s:14:"Row 4 column 3";}i:5;a:4:{s:4:"row0";s:14:"Row 5 column 0";s:4:"row1";s:14:"Row 5 column 1";s:4:"row2";s:14:"Row 5 column 2";s:4:"row3";s:14:"Row 5 column 3";}i:6;a:4:{s:4:"row0";s:14:"Row 6 column 0";s:4:"row1";s:14:"Row 6 column 1";s:4:"row2";s:14:"Row 6 column 2";s:4:"row3";s:14:"Row 6 column 3";}i:7;a:4:{s:4:"row0";s:14:"Row 7 column 0";s:4:"row1";s:14:"Row 7 column 1";s:4:"row2";s:14:"Row 7 column 2";s:4:"row3";s:14:"Row 7 column 3";}i:8;a:4:{s:4:"row0";s:14:"Row 8 column 0";s:4:"row1";s:14:"Row 8 column 1";s:4:"row2";s:14:"Row 8 column 2";s:4:"row3";s:14:"Row 8 column 3";}i:9;a:4:{s:4:"row0";s:14:"Row 9 column 0";s:4:"row1";s:14:"Row 9 column 1";s:4:"row2";s:14:"Row 9 column 2";s:4:"row3";s:14:"Row 9 column 3";}i:10;a:4:{s:4:"row0";s:15:"Row 10 column 0";s:4:"row1";s:15:"Row 10 column 1";s:4:"row2";s:15:"Row 10 column 2";s:4:"row3";s:15:"Row 10 column 3";}i:11;a:4:{s:4:"row0";s:15:"Row 11 column 0";s:4:"row1";s:15:"Row 11 column 1";s:4:"row2";s:15:"Row 11 column 2";s:4:"row3";s:15:"Row 11 column 3";}i:12;a:4:{s:4:"row0";s:15:"Row 12 column 0";s:4:"row1";s:15:"Row 12 column 1";s:4:"row2";s:15:"Row 12 column 2";s:4:"row3";s:15:"Row 12 column 3";}i:13;a:4:{s:4:"row0";s:15:"Row 13 column 0";s:4:"row1";s:15:"Row 13 column 1";s:4:"row2";s:15:"Row 13 column 2";s:4:"row3";s:15:"Row 13 column 3";}i:14;a:4:{s:4:"row0";s:15:"Row 14 column 0";s:4:"row1";s:15:"Row 14 column 1";s:4:"row2";s:15:"Row 14 column 2";s:4:"row3";s:15:"Row 14 column 3";}i:15;a:4:{s:4:"row0";s:15:"Row 15 column 0";s:4:"row1";s:15:"Row 15 column 1";s:4:"row2";s:15:"Row 15 column 2";s:4:"row3";s:15:"Row 15 column 3";}i:16;a:4:{s:4:"row0";s:15:"Row 16 column 0";s:4:"row1";s:15:"Row 16 column 1";s:4:"row2";s:15:"Row 16 column 2";s:4:"row3";s:15:"Row 16 column 3";}i:17;a:4:{s:4:"row0";s:15:"Row 17 column 0";s:4:"row1";s:15:"Row 17 column 1";s:4:"row2";s:15:"Row 17 column 2";s:4:"row3";s:15:"Row 17 column 3";}i:18;a:4:{s:4:"row0";s:15:"Row 18 column 0";s:4:"row1";s:15:"Row 18 column 1";s:4:"row2";s:15:"Row 18 column 2";s:4:"row3";s:15:"Row 18 column 3";}i:19;a:4:{s:4:"row0";s:15:"Row 19 column 0";s:4:"row1";s:15:"Row 19 column 1";s:4:"row2";s:15:"Row 19 column 2";s:4:"row3";s:15:"Row 19 column 3";}} to unserialize to this (which I can do): Array ( [0] => Array ( [row0] => Row 0 column 0 [row1] => Row 0 column 1 [row2] => Row 0 column 2 [row3] => Row 0 column 3 ) [1] => Array ( [row0] => Row 1 column 0 [row1] => Row 1 column 1 [row2] => Row 1 column 2 [row3] => Row 1 column 3 ) [2] => Array ( [row0] => Row 2 column 0 [row1] => Row 2 column 1 [row2] => Row 2 column 2 [row3] => Row 2 column 3 ) [3] => Array ( [row0] => Row 3 column 0 [row1] => Row 3 column 1 [row2] => Row 3 column 2 [row3] => Row 3 column 3 ) [4] => Array ( [row0] => Row 4 column 0 [row1] => Row 4 column 1 [row2] => Row 4 column 2 [row3] => Row 4 column 3 ) [5] => Array ( [row0] => Row 5 column 0 [row1] => Row 5 column 1 [row2] => Row 5 column 2 [row3] => Row 5 column 3 ) [6] => Array ( [row0] => Row 6 column 0 [row1] => Row 6 column 1 [row2] => Row 6 column 2 [row3] => Row 6 column 3 ) [7] => Array ( [row0] => Row 7 column 0 [row1] => Row 7 column 1 [row2] => Row 7 column 2 [row3] => Row 7 column 3 ) [8] => Array ( [row0] => Row 8 column 0 [row1] => Row 8 column 1 [row2] => Row 8 column 2 [row3] => Row 8 column 3 ) [9] => Array ( [row0] => Row 9 column 0 [row1] => Row 9 column 1 [row2] => Row 9 column 2 [row3] => Row 9 column 3 ) [10] => Array ( [row0] => Row 10 column 0 [row1] => Row 10 column 1 [row2] => Row 10 column 2 [row3] => Row 10 column 3 ) [11] => Array ( [row0] => Row 11 column 0 [row1] => Row 11 column 1 [row2] => Row 11 column 2 [row3] => Row 11 column 3 ) [12] => Array ( [row0] => Row 12 column 0 [row1] => Row 12 column 1 [row2] => Row 12 column 2 [row3] => Row 12 column 3 ) [13] => Array ( [row0] => Row 13 column 0 [row1] => Row 13 column 1 [row2] => Row 13 column 2 [row3] => Row 13 column 3 ) [14] => Array ( [row0] => Row 14 column 0 [row1] => Row 14 column 1 [row2] => Row 14 column 2 [row3] => Row 14 column 3 ) [15] => Array ( [row0] => Row 15 column 0 [row1] => Row 15 column 1 [row2] => Row 15 column 2 [row3] => Row 15 column 3 ) [16] => Array ( [row0] => Row 16 column 0 [row1] => Row 16 column 1 [row2] => Row 16 column 2 [row3] => Row 16 column 3 ) [17] => Array ( [row0] => Row 17 column 0 [row1] => Row 17 column 1 [row2] => Row 17 column 2 [row3] => Row 17 column 3 ) [18] => Array ( [row0] => Row 18 column 0 [row1] => Row 18 column 1 [row2] => Row 18 column 2 [row3] => Row 18 column 3 ) [19] => Array ( [row0] => Row 19 column 0 [row1] => Row 19 column 1 [row2] => Row 19 column 2 [row3] => Row 19 column 3 ) ) then to change it to this: Array ( [0] => Array ( [row0] => Row 0 column 0 [row1] => Row 0 column 1 ) [1] => Array ( [row0] => Row 1 column 0 [row1] => Row 1 column 1 ) [2] => Array ( [row0] => Row 2 column 0 [row1] => Row 2 column 1 ) [3] => Array ( [row0] => Row 3 column 0 [row1] => Row 3 column 1 ) [4] => Array ( [row0] => Row 4 column 0 [row1] => Row 4 column 1 ) [5] => Array ( [row0] => Row 5 column 0 [row1] => Row 5 column 1 ) [6] => Array ( [row0] => Row 6 column 0 [row1] => Row 6 column 1 ) [7] => Array ( [row0] => Row 7 column 0 [row1] => Row 7 column 1 ) [8] => Array ( [row0] => Row 8 column 0 [row1] => Row 8 column 1 ) [9] => Array ( [row0] => Row 9 column 0 [row1] => Row 9 column 1 ) [10] => Array ( [row0] => Row 10 column 0 [row1] => Row 10 column 1 ) ) and then re-serialize it. It's the re-serializing as an array so that it looks similar to the original that's got me stuck. ??? Quote Link to comment https://forums.phpfreaks.com/topic/75534-solved-how-do-i-serialize-an-array-in-a-text-file/#findComment-382198 Share on other sites More sharing options...
wildteen88 Posted October 31, 2007 Share Posted October 31, 2007 Surly the script you have allows you to change how many rows/columns there are without having to hack the default serialized array? Quote Link to comment https://forums.phpfreaks.com/topic/75534-solved-how-do-i-serialize-an-array-in-a-text-file/#findComment-382203 Share on other sites More sharing options...
Dave3765 Posted October 31, 2007 Author Share Posted October 31, 2007 Nope. The only instruction it gives is this: +++++++++++++++++++++++++++++++++++++++++++++++++++++++ The data contains a multidimensional array that consists of the data for the table. It should be in the following format: In the primary array, each element should have a key eqaul to the row id and the value is a sub array that contains column data. The column data subarray should have key values that are the column values from the db and the values are the data to be displayed. An example would be: [1] => array( [Name] => 'Some Guy' [Address] => '123 Some Street' [Phone] => '123-123-1234' ) [2] => array( [Name] => 'Some Girl' [Address] => '321 Some Drive' [Phone] => '987-987-9876' } etc. +++++++++++++++++++++++++++++++++++++++++++++++++++++++ Now that doesn't help me because I still need to re-serialize it... don't I? Quote Link to comment https://forums.phpfreaks.com/topic/75534-solved-how-do-i-serialize-an-array-in-a-text-file/#findComment-382208 Share on other sites More sharing options...
Dave3765 Posted October 31, 2007 Author Share Posted October 31, 2007 In case it helps, here is the file of the script that does the serializing and un-serializing: <?php //ini_set("display_errors", "1"); //ini_set("error_reporting", "E_ALL"); include("./AjaxTableEditor.class.php"); $at = new TableEditor; if (isset($_POST['new'])) { //You can choose to handle the data processing part of your script //this way, where it is all in one page. //Just make sure that you either return nothing on success, //or you echo out "true", otherwise it will error extract($_POST); //the script returns three values: //$rowid: the id for the row //$colid: the value for the column //$new: the value that was typed into the text input $data = file_get_contents("./tester.txt"); $data = unserialize($data); $data[$rowid][$colid] = $new; //if this were a database, you could use the following SQL statement: //UPDATE $tablename SET `$colid` = '$new' WHERE id = '$rowid' //you should do some verification on the data input by the user. $open = fopen("./tester.txt", 'w'); fwrite($open, serialize($data)); fclose($open); } else { //the display properties for the odd and even rows $odd = array('style' => 'background-color: #CCCCCC;'); $even = array('style' => 'background-color: #EEEEEE;'); //the display properties for the overall table $table = array('align' => 'center', 'cellpadding' => '3', 'cellspacing' => '0', 'width' => '50%'); //table column header information $headers = array("Supplier Name", "Website"); $headerattrib = array('style' => 'background-color: skyblue'); $at->SetEvenRowAttribs($even); $at->SetOddRowAttribs($odd); $at->SetTableAttribs($table); $at->SetHeaderAttribs($headerattrib); $at->SetHeaders($headers); $at->SetSubmit("example.php"); $data = file_get_contents("./tester.txt"); $data = unserialize($data); $at->SetData($data); echo $at->GenerateTable(); //echo "<pre>"; //print_r($data); } /* //comment out everything above, and uncomment this to rebuild the sample data for ($a = 0; $a < 20; $a++) { for ($b = 0; $b < 4; $b++) { $n[$a]["row" . $b] = "Row $a column $b"; } } $open = fopen("./tester.txt", 'w'); fwrite($open, serialize($n)); fclose($open); */ ?> Quote Link to comment https://forums.phpfreaks.com/topic/75534-solved-how-do-i-serialize-an-array-in-a-text-file/#findComment-382227 Share on other sites More sharing options...
wildteen88 Posted October 31, 2007 Share Posted October 31, 2007 Have a look at the file called exampledata2.php in the AdvATE folder to see how to create your array. Quote Link to comment https://forums.phpfreaks.com/topic/75534-solved-how-do-i-serialize-an-array-in-a-text-file/#findComment-382238 Share on other sites More sharing options...
Dave3765 Posted October 31, 2007 Author Share Posted October 31, 2007 MAN! Do I feel stupid! Defiantly should have looked in that file Thanks for your patience wildteen88 - much appreciated Quote Link to comment https://forums.phpfreaks.com/topic/75534-solved-how-do-i-serialize-an-array-in-a-text-file/#findComment-382246 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.