note 100942 added to function.yaml-parse
| From: | webmaster at mmweb-helper dot fr | Date: | Tue, 16 Nov 2010 14:15:55 +0000 |
| Subject: | note 100942 added to function.yaml-parse | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-174080@lists.php.net to get a copy of this message | ||
/** insert
* add value in file
*/
public function insert($key, $value, $file) {
$csize = $this->loadini();
if(strlen($key . $value) > $csize["string_max_size"])
return $this->error(4);
$file = $this->path . $file . ".yml";
$this->load($file);
if(file_exists($file)) {
$insert = file_get_contents($file);
if(!preg_match("/$key/i", $insert)) {
$up = fopen($file, "a");
fwrite($up, "$key : $value\n");
fclose($up);
$msg = "$key : $value was been insert into $file";
return $msg;
} else
return false;
} else
return $this->error(3);
}
/** update
* update key value in file
*/
public function update($key, $value, $file) {
$file = $this->path . $file . ".yml";
$this->load($file);
if(file_exists($file)) {
$this->elem[$key] = $value;
unlink($file);
$up = fopen($file, "a");
foreach($this->elem as $k => $v)
fwrite($up, "$k : $v\n");
fclose($up);
} else
return $this->error(3);
}
/** delete
* deleting var in file
*/
public function delete($key, $file) {
$file = $this->path . $file . ".yml";
$this->load($file);
if(file_exists($file)) {
unset($this->elem[$key]);
$this->remove($file);
$up = fopen($file, "a");
foreach($this->elem as $k => $v)
fwrite ($up, "$k : $v\n");
fclose($up);
} else
return $this->error(3);
}
/** clear
* reset the main table
*/
public function clear() {
if(isset($this->elem))
unset($this->elem);
else
return false;
}
/** search
* check assoc key with value
*/
public function search($key, $value, $file) {
$file = $this->path . $file . ".yml";
$this->load($file);
if(array_key_exists($key, $this->elem)) {
$result = array_search($value, $this->elem);
if($result == $key)
return true;
else
return false;
} else
return false;
}
/** conkey
* insert this YAML Conkey for sending yml query
*/
public function query($cmd) {
if($cmd !== null && !empty($cmd) && is_string($cmd)) {
$cmd = trim($cmd);
if(preg_match("/^INSERT (.*) : (.*) INTO (.*)$/i", $cmd, $result)) {
print "Query sended : " . $result[0]
. "\nCommande result : true"
. "\nValue : ";
return $this->insert($result[1], $result[2], $result[3]);
} elseif(preg_match("/^CREATE TABLE (.*)$/i", $cmd, $result)) {
print "Query sended : " . $result[0]
. "\nCommande result : true"
. "\nValue : ";
return $this->create($result[1]);
} elseif(preg_match("/^DROP TABLE (.*)$/i", $cmd, $result)) {
print "Query sended : " . $result[0]
. "\nCommande result : true"
. "\nValue : ";
return $this->remove($result[1]);
} elseif(preg_match("/^DELETE (.*) FROM (.*)$/i", $cmd, $result)) {
print "Query sended : " . $result[0]
. "\nCommande result : true"
. "\nValue : ";
return $this->delete($result[1], $result[2]);
} elseif(preg_match("/^UPDATE (.*) SET (.*) : (.*)$/i", $cmd, $result)) {
print "Query sended : " . $result[0]
. "\nCommande result : true"
. "\nValue : ";
return $this->update($result[2], $result[3], $result[1]);
} elseif(preg_match("/^SELECT (.*) FROM (.*)$/i", $cmd, $result)) {
print "Query sended : " . $result[0]
. "\nCommande result : true"
. "\nValue : ";
return $this->g($result[1], $result[2]);
} else
return $this->error(1);
} else
return $this->error(2);
}
/** error
* sending a message error when he has
*/
public function error($statu) {
switch($statu) {
case 1: $error_type = "syntax"; $error_msg = "Syntax error"; break;
case 2: $error_type = "invalid"; $error_msg = "Invalid parameter"; break;
case 3: $error_type = "unknow"; $error_msg = "Illegal command"; break;
case 4: $error_type = "refused"; $error_msg = "Configuration locked"; break;
default: break;
}
die("# Error type '$error_type' with message '$error_msg' #");
}
}
?>
In work source file : http://www.mmweb-helper.fr/php/scripts/yaml.rar
----
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/100942
Del: integrated -- https://master.php.net/note/delete/100942/integrated
Del: useless -- https://master.php.net/note/delete/100942/useless
Del: bad code -- https://master.php.net/note/delete/100942/bad+code
Del: spam -- https://master.php.net/note/delete/100942/spam
Del: non-english -- https://master.php.net/note/delete/100942/non-english
Del: in docs -- https://master.php.net/note/delete/100942/in+docs
Del: other reasons-- https://master.php.net/note/delete/100942
Reject -- https://master.php.net/note/reject/100942
Search -- https://master.php.net/manage/user-notes.php