Home > Backend Development > PHP Tutorial > Tips on operating files in php

Tips on operating files in php

墨辰丷
Release: 2023-03-30 18:06:01
Original
1332 people have browsed it

This article mainly introduces the related skills of php file operation. Interested friends can refer to it. I hope it will be helpful to everyone.

The details are as follows:

For example, remove the first few lines in the lrc file:

[ti:]
[ar:]
[al:]
[by:cww.99Lrc.net]
[00:00.59]dasfdasfasdf
[00:30.18]dafadsf

php implementation code is as follows:

<?php
foreach (new DirectoryIterator(&#39;./&#39;) as $fileInfo) {
  if($fileInfo->isDot()) continue;
  if($fileInfo->getExtension()=="lrc"){
    $handle = fopen($fileInfo->getFilename(), &#39;rw&#39;);
    $line_num=0;
    while(!feof($handle)){
      $str=fgets($handle, 1024);
      if(strstr($str, "www.99Lrc.net")){
        ob_start();
        fpassthru($handle);
        //fclose($handle);
        file_put_contents($fileInfo->getFilename(),ob_get_clean());
        printf(&#39;done&#39;);
        break;
      }
      $line_num++;
    }
    fclose($handle);
    echo $fileInfo->getFilename() . PHP_EOL;
  }
}
Copy after login

Summary : The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

php three recursive function implementation methods

php uses the MagickWand module to operate image additions Watermark method

PHP simulates the method of response class in asp

The above is the detailed content of Tips on operating files in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template