summaryrefslogtreecommitdiff
path: root/it.class
diff options
context:
space:
mode:
authorUrban Müller2008-12-11 19:40:45 +0000
committerUrban Müller2008-12-11 19:40:45 +0000
commit8305ec40a946ec4001af9b0721c2d960387dd81e (patch)
tree9074dc5d835e5a0905b17e10696d9e5a3645b79e /it.class
parent665902b5377084e59b4c860b0ab053a00fa1dac4 (diff)
downloaditools-8305ec40a946ec4001af9b0721c2d960387dd81e.tar.gz
itools-8305ec40a946ec4001af9b0721c2d960387dd81e.tar.bz2
itools-8305ec40a946ec4001af9b0721c2d960387dd81e.zip
handle stdin/stdout
Diffstat (limited to 'it.class')
-rw-r--r--it.class11
1 files changed, 6 insertions, 5 deletions
diff --git a/it.class b/it.class
index 28a473c..7e6e541 100644
--- a/it.class
+++ b/it.class
@@ -683,28 +683,29 @@ function mail($p)
/**
* Reads a file and returns it as string or in one of several formats. Two params: filename and flags
- * @param $filename name of file to read
+ * @param $filename name of file to read or - for stdin
* @param $p['keyval'] each line of the file is one tab-separated key/value pair, return assoc array
*/
function file_get($filename, $p = array())
{
+ $data = file_get_contents($filename == "-" ? "php://stdin" : $filename);
if ($p['keyval'])
{
- foreach (explode("\n", rtrim(file_get_contents($filename), "\n")) as $line)
+ foreach (explode("\n", rtrim($data, "\n")) as $line)
{
$arr = explode("\t", $line, 2);
$result[$arr[0]] = $arr[1];
}
}
else
- $result = file_get_contents($filename);
+ $result = $data;
return $result;
}
/**
* Write data to a file with several serialization modes
- * @param $filename name of file to write to
+ * @param $filename name of file to write or - for stdout
* @param $data data to write
* @param $p['keyval'] $data must be an assoc array and is written as tab-separated lines
*/
@@ -713,7 +714,7 @@ function file_put($filename, $data, $p = array())
if ($p['keyval'])
$data = join("", it::map('"$k\t$v\n"', $data));
- return file_put_contents($filename, $data);
+ return file_put_contents($filename == "-" ? "php://stdout" : $filename, $data);
}
}