原始文件:
PHP - 四级单词lrc文件解析为txt

转换后文件:
PHP - 四级单词lrc文件解析为txt

php代码:

  • 首先根据需要更改文件路径。
  • 转换后存放的文件要事先创建,为txt文件。
  • 核心代码:正则表达式替换:
  • PHP - 四级单词lrc文件解析为txt
<?php
	header('Content-type:text/html; charset="utf-8"');
	
	//文件存在于桌面
	$fromfilename = '1.lrc';//原始文件名称。
	$tofilename = '1_txt.txt';//转换后,存放至…………
	
	$handle = @fopen("C:\\Users\\Administrator\\Desktop\\".$fromfilename,"r");
	$fh = fopen("C:\\Users\\Administrator\\Desktop\\".$tofilename, "a");
	
	$i = 0;
	
	if ($handle) {
		while (($buffer = fgets($handle, 4096)) !== false) {
			//进行操作
			if(!($i <= 4)) {
				if($i == 5 || $i == 6) {
					//echo preg_replace ('/\[([\s\S]*)\]/', '*', $buffer).PHP_EOL;
					fwrite($fh, preg_replace ('/\[([\s\S]*)\]/', '*', $buffer).PHP_EOL);
				} else {
					//echo preg_replace ('/\[([\s\S]*)\]/', '', $buffer).PHP_EOL;
					fwrite($fh, preg_replace ('/\[([\s\S]*)\]/', '', $buffer).PHP_EOL);
				}
			}
			$i++;
		}
		if (!feof($handle)) {
			echo "Fail!";
		}
		echo 'Yes!';
		fclose($handle);
		fclose($fh);
	}
?>

 

相关文章:

  • 2022-12-23
  • 2021-05-21
  • 2021-10-05
  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
  • 2021-09-04
  • 2021-04-27
猜你喜欢
  • 2022-12-23
  • 2021-06-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
相关资源
相似解决方案