本文整理汇总了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}";
}
示例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>';
}
示例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());
}
示例4: SplFileObject
<?php
//line 2
//line 3
//line 4
//line 5
$s = new SplFileObject(__FILE__);
$s->seek(1);
echo $s->getCurrentLine();
echo $s->getCurrentLine();
示例5: SplFileObject
<?php
$splFileObject = new SplFileObject(__FILE__);
$splFileObject->setMaxLineLen(3);
$line = $splFileObject->getCurrentLine();
var_dump($line === '<?p');
var_dump(strlen($line) === 3);
示例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;
示例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);
}