JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
metaform only sends .sql file if you check 'db'. added string_array()
[wfpl.git] / string_array.php
1 <?php
2
3 #  Copyright (C) 2007 Jason Woofenden
4 #
5 #  This file is part of wfpl.
6 #
7 #  wfpl is free software; you can redistribute it and/or modify it under the
8 #  terms of the GNU Lesser General Public License as published by the Free
9 #  Software Foundation; either version 2.1 of the License, or (at your option)
10 #  any later version.
11 #
12 #  wfpl is distributed in the hope that it will be useful, but WITHOUT ANY
13 #  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 #  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
15 #  more details.
16 #
17 #  You should have received a copy of the GNU Lesser General Public License
18 #  along with wfpl; if not, write to the Free Software Foundation, Inc., 51
19 #  Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20
21
22 # This file contains code to convert an array into a string, and back again.
23
24 require_once('code/wfpl/binary.php');
25
26 function string_to_array($data) {
27         $header_count = pop_int($data);
28         $out = array();
29         while($header_count--) {
30                 $size = pop_int($data);
31                 $out[] = substr($data, 0, $size);
32                 $data = substr($data, $size);
33         }
34         return $out;
35 }
36
37 function array_to_string($array) {
38         $ret = to_raw_int(count($array));
39         foreach($array as $element) {
40                 $ret .= to_raw_int(strlen($element));
41                 $ret .= $element;
42         }
43         return $ret;
44 }
45
46 ?>