So my question is: is all this doable with an UDF?
Code: Select all
function encode_list($variables, $separator=" ") {
// Chains together the content of multiple
// variables into a single string without the
// need of separators. Such string contains a
// special header that allows extracting (single)
// variables with the companion function decode_list().
// The resulting string will have this structure:
//
// count_of_tokens;start_1-len_1#...#start_n-len_n;token_1...token_n
//
// $variables List of the variables names whose
// content you want to chain together.
// You must provide a single-quote-enclosed
// list, like '$var_1 $var_2', otherwise
// variables will be resolved.
//
// $separator Separator between variables names.
// You should use any invalid character
// in variables names, and of course any
// character not used in the variables
// names.
$counter = 0;
$start = 0;
$header = "";
$chain = "";
foreach ($variable, "$variables", "$separator") {
$len = strlen($variable);
$header = $header . $start . "-" . $len . "#";
$chain = $chain . $variable;
$start = $start + $len;
$counter++;
};
$header = substr("$header", 0, -1);
return "$counter;$header;$chain";
}
XYplorer Beta Club