CSV.php
2 years ago
Currency.php
3 years ago
Device.php
2 years ago
Number_Formatter.php
3 years ago
Option.php
2 years ago
Request.php
2 years ago
Salt.php
3 years ago
Security.php
3 years ago
Singleton.php
2 years ago
String_Util.php
3 years ago
URL.php
3 years ago
WP_Async_Request.php
3 years ago
WordPress_Site_Date_Format_Pattern.php
3 years ago
CSV.php
32 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP_SCOPED\IAWP\Utils; |
| 4 | |
| 5 | class CSV |
| 6 | { |
| 7 | private $header; |
| 8 | private $rows; |
| 9 | /** |
| 10 | * @param array $header |
| 11 | * @param array[] $rows |
| 12 | */ |
| 13 | public function __construct(array $header, array $rows) |
| 14 | { |
| 15 | $this->header = $header; |
| 16 | $this->rows = $rows; |
| 17 | } |
| 18 | public function to_string() : string |
| 19 | { |
| 20 | $delimiter = ','; |
| 21 | $enclosure = '"'; |
| 22 | $escape_character = '\\'; |
| 23 | $f = \fopen('php://memory', 'r+'); |
| 24 | \fputcsv($f, $this->header, $delimiter, $enclosure, $escape_character); |
| 25 | foreach ($this->rows as $row) { |
| 26 | \fputcsv($f, $row, $delimiter, $enclosure, $escape_character); |
| 27 | } |
| 28 | \rewind($f); |
| 29 | return \wp_kses(\stream_get_contents($f), 'strip'); |
| 30 | } |
| 31 | } |
| 32 |