dro62273 2014-03-31 09:13
浏览 63

使用PHP编辑多个.php文件

I want to edit 100 php files in different folders using php. I have searched on google but doesn't get any help. I want to replace some text with other text on every file. Tell me a suitable way to do it using php.

For eg. I have two texts t1 ,t2 and i want to replace it with v1,v2 in every file how to do it?.

  • 写回答

2条回答 默认 最新

  • douliao8760 2014-03-31 09:25
    关注
    $files = array(
        'directory/file1.php',
        'directory/file2.php'
    )
    
    $t1 = 'your text 1';
    $t2 = 'your text 2';
    
    $t1 = 'your version 1';
    $t2 = 'your version 2';
    
    foreach($files as $f) {
       $old_content = file_get_contents($f);
       $new_content = str_replace($t1, $v1, $old_content);
       $new_content = str_replace($t2, $v2, $new_content);
       file_put_contents($f, $new_content);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据