1

I'm creating a language learning website and in one section I'd like to have many pages each with a table of verb conjugations. It'll take ages to do each one manually, so I'd like to know if there's a way of creating a datafile that can be read from an html page, perhaps javascript or php, and data imported into the table.

Each verb would have its own datafile, which would contain an array that ideally looked like this:

pren,prenn,av,ys,yn,owgh,ons,ir,is,sys,as,syn,sowgh,sons,as,en,es,a,en,ewgh,ens,ys,sen,ses,sa,sen,sewgh,sens,sys,iv,y,o,yn,owgh,ons,er,en,es,a,en,ewgh,ens,ys,ys

Then in the table I would specify which datafile to import, and call different entries in the array at the appropriate places to build up a verb table, so 1 and 3 would give prenav, 1 and 4 would give prenys, etc.

Does anyone know how this could be done?

4

2 回答 2

0

您可以在 PHP 中使用file_get_contents和的组合来执行此操作explode

file_get_contents将读取数据文件,您可以将其存储在字符串中,如下所示:

$datafile = file_get_contents('pren.txt');

将数据文件保存在字符串变量中后,可以使用explode将其拆分为数组,如下所示:

$datafileArray = explode(',', $datafile);

现在您可以使用数字索引访问数组的成员,尽管需要注意的一点是它是从零开始的索引。所以它会是 0 和 2 让你'prenav',而不是 1 和 3:

echo $dataFileArray[0] . $dataFileArray[2]; // "prenav"
echo $dataFileArray[0] . $dataFileArray[3]; // "prenys"
于 2012-11-14T19:28:12.613 回答
0

假设每个动词的文件名与动词同名,文件直接在工作中,动词存储在 $verbs 中,你可以这样做:

<table>
<tr><td>Verb</td><td>Conjugation</td></tr>
<?php
foreach ($verbs as $verb) {
$conjugations = file_get_contents($verb);
echo "</tr><td>$verb</td><td>$conjugations</td><tr>";
}
?>
</table>
于 2012-11-14T19:40:33.230 回答