0

だから私は次のようなcsvファイルを持っています

Name1,url1
Name2,url2
Name3,url3

csv の各行を調べて、名前を Web サイトと比較するための JavaScript (必要に応じて PHP も使用できます) を作成したいと思います。ページの左上の四分円は「名前」を表示するボックスであり、ページの右半分はURLをロードし、左下の四分円には左右の矢印があり、クリックしてCSV内を移動できます。

ページを分割するために iFrame を検討しています。本当の課題は、CSV での読み込みです。私はphpでこれを行い、すべてのデータをhtmlページに配置することを検討していましたが、私のCSVが大きい場合、これは問題になる可能性があります.

この問題に正しい方法で取り組んでいますか?

4

2 に答える 2

1

In PHP you will want to use fgetcsv().

<?php
if (($handle = fopen("test.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        list($name, $url) = $data;
        // do something with $name and $data
    }
    fclose($handle);
}

Just bear in mind a few things:

  • If this file needs to be read frequently you're going to run into I/O problems.
  • If this file needs to be written to frequently you're going to run into I/O problems much more quickly.
  • Try not to store any more than the bear minimum of rows in memory, otherwise you may bump up against PHP's memory limits.
  • CSV bad, database good.
于 2013-04-25T22:14:16.717 に答える