/** * * explode多次转换 ... * @param unknown_type $row * @param unknown_type $delimiter */ function explodes($row, $delimiter) { if (is_array($delimiter)) { foreach ($delimiter as $v) { $row = explodes($row, $v); } } else { if (is_array($row)) { $_row = array(); foreach ($row as $vv) { $expval = $vv ? explode($delimiter, $vv) : array(); $expval && ($_row[$expval[0]] = $expval[1]); } $row = $_row; } elseif (is_string($row)) { $row = $row ? explode($delimiter, $row) : array(); } } return $row; }
public function dataFormat($format, $row) { if (is_array($format) && $format) { foreach ($format as $k => $v) { if (isset($row[$k])) { if ($v['type'] == 'date') { $row[$k] = $row[$k] ? date($v['format'], $row[$k]) : ''; } elseif ($v['type'] == 'array') { $row[$k] = $row[$k] ? call_user_func('maybe_' . $v['format'], $row[$k]) : array(); } elseif ($v['type'] == 'explode') { $row[$k] = explodes($row[$k], $v['delimiter']); } } } } return $row; }
function newcontent($url) { $ym = file_get_contents($url); $ym = explodes('<content>', '</content>', $ym); return $ym; }