diff options
Diffstat (limited to 'library/Reporting/Str.php')
-rw-r--r-- | library/Reporting/Str.php | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/library/Reporting/Str.php b/library/Reporting/Str.php new file mode 100644 index 0000000..d4c7355 --- /dev/null +++ b/library/Reporting/Str.php @@ -0,0 +1,37 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting; + +class Str +{ + public static function putcsv(array $data, $delimiter = ',', $enclosure = '"', $escape = '\\') + { + $fp = fopen('php://temp', 'r+b'); + + foreach ($data as $row) { + fputcsv($fp, $row, $delimiter, $enclosure, $escape); + } + + rewind($fp); + + $csv = stream_get_contents($fp); + + fclose($fp); + + $csv = rtrim($csv, "\n"); // fputcsv adds a newline + + return $csv; + } + + public static function contains($haystack, $needle) + { + foreach ((array) $needle as $n) { + if (\strpos($haystack, $n) !== false) { + return true; + } + } + + return false; + } +} |