diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:28:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:28:59 +0000 |
commit | 978a1651bac3faf5e91ddba327bf39aeb6a4cb63 (patch) | |
tree | f0d1fee61877df200ccfb1c0af58a39cd551fb46 /library/Reporting/Str.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-reporting-978a1651bac3faf5e91ddba327bf39aeb6a4cb63.tar.xz icingaweb2-module-reporting-978a1651bac3faf5e91ddba327bf39aeb6a4cb63.zip |
Adding upstream version 0.10.0.upstream/0.10.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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; + } +} |