# jc-importer/2.15.0/class/Common/Importer/Parser/CSVParser.php

Import WP – CSV &amp; XML Import Export for WordPress, version 2.15.0. 45 lines.

- Page: https://pluginprobe.com/plugins/jc-importer/2.15.0/code/class/Common/Importer/Parser/CSVParser.php
- Raw: https://pluginprobe.com/plugins/jc-importer/2.15.0/raw/class/Common/Importer/Parser/CSVParser.php
- Modified: 2024-02-13T21:08:10+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/jc-importer/2.15.0/code/class/Common/Importer/Parser/CSVParser.php#L10-L20`.

```php
<?php

namespace ImportWP\Common\Importer\Parser;

use ImportWP\Common\Importer\File\CSVFile;
use ImportWP\Common\Importer\ParserInterface;

/**
 * @property CSVFile $file
 */
class CSVParser extends AbstractParser implements ParserInterface
{
    /**
     * CSV Record
     *
     * @var array
     */
    private $csv_record;

    public function query($query)
    {
        return isset($this->csv_record[$query]) ? $this->csv_record[$query] : '';
    }

    protected function onRecordLoaded()
    {
        $this->csv_record = str_getcsv($this->record, $this->file->getDelimiter(), $this->file->getEnclosure());
    }

    public function record()
    {
        return $this->csv_record;
    }

    public function query_matches($matches)
    {
        // make sure the selector is numeric {0}
        if (isset($matches[0]) && preg_match('/^\d+$/', $matches[1]) === 1) {
            return parent::query_matches($matches);
        }

        return $matches[0];
    }
}

```
