PHP code example of omegacode / php-parsecsv-validator
1. Go to this page and download the library: Download omegacode/php-parsecsv-validator library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
omegacode / php-parsecsv-validator example snippets
$header = ['title', 'price', 'categories', 'attributes'];
$reqHeaders = ['title', 'price'];
$validator = new CsvValidator($csv);
$validator
->validateHeadersAreEqual($header)
->validateDataStructure($header)
->validateDataForRequiredHeaders($reqHeaders])
;
if (count($validator->getErrors() > 0) {
// file is invalid. check the errors.
} else {
// file is valid. continue coding.
}