$val) { if ($key == $row_tag) { for ($i = 0; $i < count($val); $i += 2) { $off = $val[$i] + 1; $arr = array_slice($values, $off, $val[$i + 1] - $off); $tmp = array(); foreach ($arr as $key2 => $val2) { if (isset($val2['value'])) $tmp[$val2['tag']] = $val2['value']; else $tmp[$val2['tag']] = null; // The empty element } array_push($ret, $tmp); } } else { continue; } } return new KjwArrayResultSet($ret); } function kjwresultset_to_raw_xml(&$result, $row_tag = 'row', $root_tag = 'ROOT') { $at = $result->at(); $result->seekAbs(0); $ret = array(); array_push($ret, '<' . $root_tag . '>'); while (($row = $result->getNext())) { array_push($ret, ' <' . $row_tag . '>'); foreach ($row as $key => $val) { array_push($ret, ' <' . $key . '>' . htmlentities($val, ENT_COMPAT, 'UTF-8') . ''); } array_push($ret, ' '); } array_push($ret, ''); $result->seekAbs($at); return implode("\n", $ret); } function kjwresultset_from_csv($csv_without_head, $delimiter = ',') { preg_match(); } function kjwresultset_from_csv_with_head($csv, $delimiter = ',') { if (($resultset = kjwresultset_from_csv($csv, $delimiter)) === null) return null; if (($head = $resultset->getNext()) === false) { $resultset->destroy(); return null; } $ret = array(); while (($row = $result->getNext())) { foreach ($head as $value) { $ret[$value] = array_shift($row); } } return new KjwArrayResultSet($ret); } function kjwresultset_to_csv(&$result, $delimiter = ',', $with_head = false) { $at = $result->at(); $result->seekAbs(0); $ret = array(); // Get first row and use it as header if (($row = $result->getNext()) === false) return ''; if ($with_head) { $columns = array(); foreach (array_keys($row) as $value) { if (strpos($value, $delimiter) === false && strpos($value, '"') === false) array_push($columns, $value); else array_push($columns, '"' . str_replace('"', '""', $value) . '"'); } array_push($ret, $columns); } // Print all rows do { $columns = array(); foreach ($row as $value) { if (strpos($value, $delimiter) === false && strpos($value, '"') === false) array_push($columns, $value); else array_push($columns, '"' . str_replace('"', '""', $value) . '"'); } array_push($ret, $columns); } while (($row = $result->getNext())); // Reset result and return csv $result->seekAbs($at); return implode("\n", $ret); } function kjwresultset_to_csv_with_head(&$result, $delimiter = ',') { return kjwresultset_to_csv($result, $delimiter, true); } ?>