note 100940 added to function.yaml-parse

From: Date: Tue, 16 Nov 2010 14:13:19 +0000
Subject: note 100940 added to function.yaml-parse
Groups: php.notes 
Request: Send a blank email to php-notes+get-174078@lists.php.net to get a copy of this message
because it's too long i have separed in 2 part this class <?php /** WYml.class.php * Copyright 2010 BEBIEN Michel * YAML Parser reader and editor */ class WYml { private static $instance = null; public $elem = array(); private function __construct() {} /** getInstance * to load singletone */ public static function getInstance() { if(self::$instance === null) self::$instance = new WYml(); return self::$instance; } /** installer * add yml ini file for default use */ public function installer($path, $file) { if(!file_exists($path) && !is_dir($path)) mkdir($path, 0700, true); if(!file_exists($path . $file . ".ini")) { $default_value = array( "yml_path" => "\"$path\"", "encoding" => "\"ISO-8859-1\"", "file_max_size" => 48, "string_max_size" => 1024 ); $up = fopen($path . $file . ".ini", "a"); foreach($default_value as $k => $v) fwrite($up, "$k = $v\n"); fclose($up); } return $this->ini = $path . $file . ".ini"; } /** loadini * check default value for YAML Widget */ public function loadini() { $ini_array = parse_ini_file($this->ini, true); return $ini_array; } /** ymlsize * check file size and return an array with diferent values */ public function ymlsize($file) { $file = $this->path . $file . ".yml"; if(file_exists($file)) { $this->size = array(); $this->size["o"] = filesize($file); $this->size["ko"] = filesize($file) / 1000; $this->size["mo"] = filesize($file) / 1000000; return $this->size; } else return false; } /** encoding * force encoding string ( ISO-8859-1 and UTF-8 only ) */ public function encoding($string) { if(is_string($string)) { if($this->g("encoding", $this->ini) == "ISO-8859-1") return utf8_decode($string); elseif($this->g("encoding", $this->ini) == "UTF-8") return utf8_encode($string); } else return $this->error(2); } /** ymlpath * force yml path */ public function path($path) { if(is_dir($path)) return $this->path = $path; else return $this->error(3); } /** create * create yml file */ public function create($file) { $file = $this->path . $file . ".yml"; if(!file_exists($file)) { $up = fopen($file, "w+"); fwrite($up, ""); fclose($up); $msg = "File : $file was been created"; return $msg; } else return false; } /** remove * for deleting file */ public function remove($file) { $file = $this->path . $file . ".yml"; if(file_exists($file)) { unlink($file); $msg = "File : $file was been deleted"; return $msg; } else return $this->error(3); } /** load * open read and parse yml file */ public function load($file) { $this->clear(); if(file_exists($file)) { $this->file = file_get_contents($file); preg_match_all("/(.*):(.*)/i", $this->file, $this->content); $this->elem = array_combine($this->content[1], $this->content[2]); foreach($this->elem as $k => $v) { $this->elem[trim($k)] = trim($v); if(preg_match("/\s/", $k)) unset($this->elem[$k]); } return $this->elem; } else return $this->error(3); } /** g * get value in elem table */ public function g($var = null, $file) { $file = $this->path . $file . ".yml"; $this->load($file); if(isset($this->elem)) { if($var === null) return $this->elem; else { if(array_key_exists($var, $this->elem)) return $this->elem["$var"]; else return false; } } else return $this->error(3); } ---- Server IP: 195.221.21.36 Probable Submitter: 80.9.145.145 ---- Manual Page -- http://www.php.net/manual/en/function.yaml-parse.php Edit -- https://master.php.net/note/edit/100940 Del: integrated -- https://master.php.net/note/delete/100940/integrated Del: useless -- https://master.php.net/note/delete/100940/useless Del: bad code -- https://master.php.net/note/delete/100940/bad+code Del: spam -- https://master.php.net/note/delete/100940/spam Del: non-english -- https://master.php.net/note/delete/100940/non-english Del: in docs -- https://master.php.net/note/delete/100940/in+docs Del: other reasons-- https://master.php.net/note/delete/100940 Reject -- https://master.php.net/note/reject/100940 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#174078) next »