使用php从文本文件中读取逗号分隔值

San*_*ool -2 php file

我有一个文本文件,其中包含逗号分隔的内容.

让我的文件test.txt.内容是:

text1, text2, text3
Run Code Online (Sandbox Code Playgroud)

我想读取这个文件并将这三个值分配给3个变量.

我检查过 readfile(filename,include_path,context)

Nin*_*nju 5

试试这个

$textCnt  = "text.txt";
$contents = file_get_contents($textCnt);
$arrfields = explode(',', $contents);

echo $arrfields[0]; 
echo $arrfields[1]; 
echo $arrfields[2]; 
Run Code Online (Sandbox Code Playgroud)

或者,在循环中:

foreach($arrfields as $field) {
    echo $field;
}
Run Code Online (Sandbox Code Playgroud)