note 63563 deleted from ref.array by bjori

From: Date: Thu, 23 Mar 2006 23:29:53 +0000
Subject: note 63563 deleted from ref.array by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-106499@lists.php.net to get a copy of this message
Note Submitter: attes.homeip.net Reason: bad code ---- Converts multilevel array with keys to text and back. No failsafe yet. <?php function totxt($ar) { foreach ($ar as $k=>$v) { if (is_array($v)) { $i.='!!'.base64_encode($k).''.totxt($v).'!)'; } else { $i.='!.'.base64_encode($k).'!'.base64_encode($v); }; }; return $i; } function toarr($tx) { $ar=array(); if ($tx) { $ok=1; while ($ok && $tx) { $i=substr($tx,0,2); switch ($i) { case '!.': $v=strpos($tx,'!',2); $e=strpos($tx,'!',$v+1); if (!$e) {$e=strlen($tx);}; $k=base64_decode(substr($tx,2,$v-2)); $v=base64_decode(substr($tx,$v+1,$e-$v-1)); $tx=substr($tx,$e); $ar[$k]=$v; break; case '!!': $v=strpos($tx,'!',2); $e=strpos($tx,'!)',$v+1); if (!$e) {$e=strlen($tx);}; $k=base64_decode(substr($tx,1,$v-1)); $v=toarr(substr($tx,$v,$e-$v)); $ar[$k]=$v; $tx=substr($tx,$e+2); break; case '!)'; $tx=substr($tx,2); break; default: $v=strpos($tx,'!',2); $tx=substr($tx,$v); break; } } } return $ar; } ?>

« previous php.notes (#106499) next »