我有一个文本文件,其中包含逗号分隔的内容.
让我的文件test.txt.内容是:
text1, text2, text3
Run Code Online (Sandbox Code Playgroud)
我想读取这个文件并将这三个值分配给3个变量.
我检查过 readfile(filename,include_path,context)
试试这个
$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)
| 归档时间: |
|
| 查看次数: |
2601 次 |
| 最近记录: |