Commit 33813073 authored by Kjartan's avatar Kjartan

- Changed field_get/set() to be more efficent.

parent 0743b2cd
...@@ -191,34 +191,14 @@ function form_submit($value) { ...@@ -191,34 +191,14 @@ function form_submit($value) {
} }
function field_get($string, $name) { function field_get($string, $name) {
foreach (explode(",", $string) as $data) { ereg(",$name=([^,]+)", ",$string", $regs);
$entry = explode("=", $data); return $regs[1];
if ($entry[0] == $name) return $entry[1];
}
} }
function field_set($string, $name, $value) { function field_set($string, $name, $value) {
if (!$value) { $rval = ereg_replace(",$name=[^,]+", "", ",$string");
// remove entry: if ($value) $rval .= ($rval == "," ? "" : ",") ."$name=$value";
foreach (explode(",", $string) as $data) { return substr($rval, 1);
$entry = explode("=", $data);
if ($entry[0] != $name) $rval .= "$entry[0]=$entry[1],";
}
}
else if (strstr($string, "$name=")) {
// found: update exsisting entry:
foreach (explode(",", $string) as $data) {
$entry = explode("=", $data);
if ($entry[0] == $name) $entry[1] = $value;
$rval .= "$entry[0]=$entry[1],";
}
}
else {
// not found:
$rval = "$string$name=$value,";
}
return $rval;
} }
function field_merge($a, $b) { function field_merge($a, $b) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment