Advertisement
Guest User

pluck-cms data format

a guest
Mar 31st, 2010
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.81 KB | None | 0 0
  1. <?php
  2. function save_file($file, $content, $chmod = 0777) {
  3.     if (is_array($file))
  4.         rename($file[0], $file[1]);
  5.     else
  6.         $file = array(1 => $file);
  7.  
  8.     $data = fopen($file[1], 'w');
  9.     fputs($data, '<?php return '.create_file_array($content).';?>');
  10.     fclose($data);
  11.     @chmod($file[1], $chmod);
  12. }
  13.  
  14. function create_file_array($array) {
  15.     $final_data = '';
  16.     foreach ($array as $key => $value) {
  17.         if (is_array($value))
  18.             $final_data .=  '\''.$key.'\'=>'.create_file_array($value).',';
  19.  
  20.         elseif (is_bool($value)) {
  21.             if ($value)
  22.                 $value = 'true';
  23.             else
  24.                 $value = 'false';
  25.         }
  26.  
  27.         elseif (is_int($value) || is_float($value))
  28.             $value = (string) $value;
  29.  
  30.         else
  31.             $value = '\''.$value.'\'';
  32.  
  33.         $final_data .=  '\''.$key.'\'=>'.$value.',';
  34.     }
  35.  
  36.     return 'Array('.rtrim($final_data, ',').')';
  37. }
  38. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement