如何根据PHP中的一行拆分文件?
我有一个名为doremi.txt的文件,如下所示,
These are the notes
I sing
They fly and dance
like a bird's wing
--------------------
Do
Re
Mi
Fa
So
La
Ti
TaDa!
我想使用此文件阅读文本文件,但我只想要在虚线之后的信息(音符注释):
// filename in this case is DoReMi.txt
$file = fopen ( $filename, 'r' );
$fileContents = nl2br ( fread ( $file, filesize( $filename )));
$lines = 0;
while(!feof($file)){
$curr = fgets($file, 999);
$lines++;
// this should count the number of lines in the text file
}
echo "--------------------";
// This is my problem area
// I want to "ignore" the information before this line
fclose( $file );
echo "# of notes: $lines";
echo "<hr/> $fileContents <hr/>";
因为这是一个文件,而不是一个文件字符串或列表,我知道我无法创建子字符串或新数组。
此外,FGETSCSV无法使用,因为它是单行而不是文件中的每一行。
I have a file named doremi.txt, which goes as follows
These are the notes
I sing
They fly and dance
like a bird's wing
--------------------
Do
Re
Mi
Fa
So
La
Ti
TaDa!
I want to read through the text file using this, but I only want the information that is after the dashed line (the musical notes):
// filename in this case is DoReMi.txt
$file = fopen ( $filename, 'r' );
$fileContents = nl2br ( fread ( $file, filesize( $filename )));
$lines = 0;
while(!feof($file)){
$curr = fgets($file, 999);
$lines++;
// this should count the number of lines in the text file
}
echo "--------------------";
// This is my problem area
// I want to "ignore" the information before this line
fclose( $file );
echo "# of notes: $lines";
echo "<hr/> $fileContents <hr/>";
Since this is a file and not a string or a list, I know that I cannot create a substring or new array.
In addition, fgetscsv wouldn't work because it is a single line rather than each line in the file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论