当前位置: 首页>>代码示例>>PHP>>正文


PHP SplFileObject::getCurrentLine方法代码示例

本文整理汇总了PHP中SplFileObject::getCurrentLine方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileObject::getCurrentLine方法的具体用法?PHP SplFileObject::getCurrentLine怎么用?PHP SplFileObject::getCurrentLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SplFileObject的用法示例。


在下文中一共展示了SplFileObject::getCurrentLine方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: processCsv

function processCsv($file, $omitTitles = true)
{
    $csv = new SplFileObject($file);
    $records = 0;
    if ($omitTitles) {
        // Get the first line but do nothing with it
        $csv->getCurrentLine();
    }
    while (!$csv->eof()) {
        // Get the current line
        $line = $csv->fgetcsv();
        // Skip blank lines that return a single null element
        if (count($line) > 1 && !is_null($line[0])) {
            (yield $line);
            $records++;
        }
    }
    return "{$records} records processed from {$file}";
}
开发者ID:sydorenkovd,项目名称:php7_EasyWay,代码行数:19,代码来源:generator_return.php

示例2: SplFileObject

<?php

$file = new SplFileObject('names.csv');
// Discard the column headers
$file->getCurrentLine();
// Build a multidimensional array of the remaining lines
while (!$file->eof()) {
    $line = $file->fgetcsv();
    // Ignore empty lines
    if (!is_null($line[0])) {
        $names[] = $line;
    }
}
/*
 * sort function, if first is bigger than second return -1, else return 1, or 0 if it's equals
 */
usort($names, function ($a, $b) {
    return [$a[1], $a[0]] <=> [$b[1], $b[0]];
});
// Display the names
foreach ($names as $name) {
    echo implode(' ', $name) . '<br>';
}
开发者ID:sydorenkovd,项目名称:php7_EasyWay,代码行数:23,代码来源:spaceship_operator.php

示例3: array

/**
 * @author  Atanas Vasilev
 * @link    http://pastebin.com/dHbqjUNy
 * @see     http://www.dotvoid.com/2010/04/detecting-utf-bom-byte-order-mark/
 * @version 1.1
 */
// SETTINGS
////////////////////////////////////////////////////////////////////////////////
$check_extensions = array('php');
// MAIN
////////////////////////////////////////////////////////////////////////////////
define('STR_BOM', "");
$file = null;
$directory = getcwd();
$rit = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST);
echo '<h1>BOM Check</h1>';
try {
    foreach ($rit as $file) {
        if ($file->isFile()) {
            $path_parts = pathinfo($file->getRealPath());
            if (isset($path_parts['extension']) && in_array($path_parts['extension'], $check_extensions)) {
                $object = new SplFileObject($file->getRealPath());
                if (false !== strpos($object->getCurrentLine(), STR_BOM)) {
                    echo $file->getRealPath() . '<br />';
                }
            }
        }
    }
} catch (Exception $e) {
    die('Exception caught: ' . $e->getMessage());
}
开发者ID:darwinv,项目名称:vogues,代码行数:31,代码来源:bom_check.php

示例4: SplFileObject

<?php

//line 2
//line 3
//line 4
//line 5
$s = new SplFileObject(__FILE__);
$s->seek(1);
echo $s->getCurrentLine();
echo $s->getCurrentLine();
开发者ID:lsqtongxin,项目名称:hhvm,代码行数:10,代码来源:fileobject_getcurrentline_basic.php

示例5: SplFileObject

<?php

$splFileObject = new SplFileObject(__FILE__);
$splFileObject->setMaxLineLen(3);
$line = $splFileObject->getCurrentLine();
var_dump($line === '<?p');
var_dump(strlen($line) === 3);
开发者ID:zaky-92,项目名称:php-1,代码行数:7,代码来源:ext_spl_tests_bug67805.php

示例6: getcwd

$str = 'Container';
$file = null;
$directory = getcwd();
$directory = './';
echo '<xmp>';
$rit = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST);
try {
    $count = 0;
    foreach ($rit as $file) {
        //print 'processing ' . $file->getRealPath()."\n";
        if ($file->isFile()) {
            $path_parts = pathinfo($file->getRealPath());
            if ('php' == $path_parts['extension']) {
                $object = new SplFileObject($file->getRealPath());
                while (!$object->eof()) {
                    $line = $object->getCurrentLine();
                    if (false !== ($pos = strpos($line, $str))) {
                        $count++;
                        print $file->getRealPath() . "\n";
                        print $line;
                        print substr($line, $pos);
                        break;
                    }
                }
            }
        } else {
            //print 'processing ' . $file->getRealPath()."\n";
            flush();
        }
    }
    echo 'done ' . $count . ' files found with ' . $str;
开发者ID:bklein01,项目名称:Project-Pier,代码行数:31,代码来源:find.php

示例7: factor

 /**
  * @return \Mathielen\ImportEngine\Storage\Format\Format
  */
 public function factor($uri)
 {
     $file = new \SplFileObject($uri);
     $delimiter = $this->guessDelimiter(utf8_encode($file->getCurrentLine()));
     return new CsvFormat($delimiter);
 }
开发者ID:mathielen,项目名称:import-engine,代码行数:9,代码来源:CsvAutoDelimiterFormatFactory.php


注:本文中的SplFileObject::getCurrentLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。