1

という名前のテキスト ファイルがあるとしますname.txt。その中に次のような内容があります。

Michal Guiles,Tanika Mcall,Jerry Sanipasi,Fallon Mcgillivray,Kurtis Bouras,Maria Teschner,Jerry Barbot,Earnestine

という名前の変数にすべての名前を入れる方法$name; 次に、それらを1つずつ出力します$comment->setname("$name");

4

2 に答える 2

3

ファイルを読む:

$file_handle = fopen("myfile.text", "r");
while (!feof($file_handle)) {
   $line = fgets($file_handle);
}
fclose($file_handle);

パーツを分割します:

$parts = explode(",",$line);

それらを1つずつ印刷します:

foreach ($parts as $part)
{
    echo "$part<br/>";
}
于 2012-04-06T10:08:54.423 に答える
2

一度に複数のことを尋ねています。次のことを 1 つずつ実行します。

  1. ファイルを読み取ります: (「 」を参照file_get_contents)

    $text = file_get_contents('name.txt');
    
  2. 名前を取得します: ( を参照explode)

    $names = explode(',', $text);
    
  3. 名前を繰り返します: ( を参照foreach)

    foreach ($names as $name)
    {
        $comment->setname($name);
    }
    
于 2012-04-06T10:31:46.533 に答える