我有這個PHP錯誤,但腳本的作品。我認爲第一個是正確的,只有第二個有這個錯誤。vprintf()參數太少
vprintf(): Too few arguments
function CreateLangTable($csvFile, $startRow, $endRow, $number) {
global $lang_code1, $lang_code2, $vocabulary_group, $teilurl;
if ($endRow < $startRow) {
return;
}
echo '
<a id="' . $vocabulary_group[$teilurl[4]][$number] . '"></a>
<table class="table-vocabulary">
<thead>';
$csvFile->seek($startRow);
vprintf('
<tr>
<th><div data-text="%1$s" data-lang="' . $lang_code1 . '" class="trigger_play"> %1$s</div></th>
<th><div data-text="%2$s" data-lang="' . $lang_code2 . '" class="trigger_play"> %2$s</div></th>
</tr>
</thead>
<tbody>', $csvFile->current());
while ($csvFile->key() <= $endRow) {
$csvFile->next();
vprintf('
<tr>
<td><div data-text="%1$s" data-lang="' . $lang_code1 . '" class="trigger_play"> %1$s</div></td>
<td><div data-text="%2$s" data-lang="' . $lang_code2 . '" class="trigger_play"> %2$s</div></td>
</tr>', $csvFile->current());
}
echo '
</tbody>
</table>' . "\n";
}
我已經在另一個答案閱讀與sprintf的()toescape的$
爲\$
一個問題,但我會得到很多這樣的錯誤的。
例如csv文件
th-value 1,th-Wert 1
value 2,Wert 2
value 3,Wert 3
value 4,Wert 4
value 5,Wert 5
th-value 1,th-Wert 1
value 2,Wert 2
value 3,Wert 3
value 4,Wert 4
value 5,Wert 5
我用這個代碼來生成正確的表:
CreateLangTable($file, 0, 4, 0);
CreateLangTable($file, 6, 9, 1);
如果我改變4〜3,9〜8中的錯誤都沒有了,但是爲什麼呢?
當你接觸不到的地方'$ csvFile'做的最後一個元素'next'獲取你什麼呢? –
@u_mulder我現在已經發布了整個功能。 – Grischa
似乎@u_mulder建議您在到達$ $ endRow後檢查$ csvFile-> current()中的內容。你可以使用XDebug來找到它,或者在$ csvFile-> next()後面添加一個'var_dump($ csvFile-> current())'來檢查每一行的值。通過這種方式,您可以確認實際上是否所有行都有至少兩個值的數組。 –