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