예제 #1
0
 function editlineinfile($find, $replace, $where)
 {
     // edit a line containing  $find, replace it... to edit especially /etc/apt/sour/sources.list file
     debugecho("\n replaceline: ({$find} -> {$replace}) in ({$where}) \n ");
     $filearr = @file($where);
     if (!$filearr) {
         echo "cannot open file... returning...\n";
         return false;
     }
     //else print_r($file);
     $newfile = array();
     foreach ($filearr as $line) {
         $line = trim($line) . "\n";
         $line = str_replace($find, $replace, $line);
         $newfile[] = $line;
     }
     arraytofile($where, $newfile);
 }
예제 #2
0
파일: localutils.php 프로젝트: jprice/EHCP
 function addifnotexists($what, $where)
 {
     debugecho("\naddifnotexists: ({$what}) -> ({$where}) \n ", 4);
     #bekle(__FUNCTION__." basliyor..");
     $what .= "\n";
     $filearr = @file($where);
     if (!$filearr) {
         echo "cannot open file, trying to setup: ({$where})\n";
         $fp = fopen($where, 'w');
         fclose($fp);
         $filearr = file($where);
     }
     //else print_r($file);
     if (array_search($what, $filearr) === false) {
         echo "dosyada bulamadı ekliyor: {$where} -> {$what} \n";
         $filearr[] = $what;
         arraytofile($where, $filearr);
     } else {
         //echo "buldu... sorun yok. \n";
         // already found, so, do not add
     }
     #bekle(__FUNCTION__." bitti...");
 }