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) {
}
function field_get($string, $name) {
foreach (explode(",", $string) as $data) {
$entry = explode("=", $data);
if ($entry[0] == $name) return $entry[1];
}
ereg(",$name=([^,]+)", ",$string", $regs);
return $regs[1];
}
function field_set($string, $name, $value) {
if (!$value) {
// remove entry:
foreach (explode(",", $string) as $data) {
$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;
$rval = ereg_replace(",$name=[^,]+", "", ",$string");
if ($value) $rval .= ($rval == "," ? "" : ",") ."$name=$value";
return substr($rval, 1);
}
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