Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Скриптовые языки программирования > PHP
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 10.01.2009, 15:26   #1
france@
 
Регистрация: 06.01.2009
Сообщений: 7
По умолчанию убрать строки из файлов

Есть много фаилов текстовых, в них есть одинаковые строки, как програмно убрать эти строки из всех фаилов и обьеденить их в один ? большое спасибо заранее.
france@ вне форума Ответить с цитированием
Старый 10.01.2009, 16:19   #2
wall66
Участник клуба
 
Аватар для wall66
 
Регистрация: 04.10.2008
Сообщений: 1,485
По умолчанию

берешь все файлы в переменные (file_get_contents), заменяешь в них нужные строки на пустые (str_replace), склеиваешь в одну переменную ($a=$b.$c;), записываешь переменную в фаил (fopen, fwrite)
свободен...
wall66 вне форума Ответить с цитированием
Старый 10.01.2009, 23:44   #3
france@
 
Регистрация: 06.01.2009
Сообщений: 7
По умолчанию

а как много файлов в массив загнать? в папке много файлов, названия всегда разные.
france@ вне форума Ответить с цитированием
Старый 11.01.2009, 00:25   #4
wall66
Участник клуба
 
Аватар для wall66
 
Регистрация: 04.10.2008
Сообщений: 1,485
По умолчанию

PHP код:
chdir('/home/site/www/docs/');
$files=array();
foreach (
glob("*.txt") as $filename) {
    
$files[]=file_get_contents($filename);

свободен...
wall66 вне форума Ответить с цитированием
Старый 11.01.2009, 00:58   #5
france@
 
Регистрация: 06.01.2009
Сообщений: 7
По умолчанию

вот нашел скриптик, а как мне обьеденить все файлы ?

PHP код:
<?php

  
////////////////////////////////////////////////////////// 

  // Рекурсивная функция - спускаемся вниз по каталогу 

  ////////////////////////////////////////////////////////// 

  
function scan_dir($dirname

  { 

    
// Объявляем переменные замены глобальными 

    
GLOBAL $text$retext

    
// Открываем текущую директорию 

    
$dir opendir($dirname); 

    
// Читаем в цикле директорию 

    
while (($file readdir($dir)) !== false

    { 

      
// Если файл обрабатываем его содержимое 

      
if($file != "." && $file != ".."

      { 

        
// Если имеем дело с файлом - производим в нём замену 

        
if(is_file($dirname."/".$file)) 

        { 

          
// Читаем содержимое файла 

          
$content file_get_contents($dirname."/".$file); 

          
// Осуществляем замену 

          
$content str_replace($text$retext$content); 

          
// Перезаписываем файл 

          
file_put_contents($dirname."/".$file,$content); 

        } 

        
// Если перед нами директория, вызываем рекурсивно 

        // функцию scan_dir 

        
if(is_dir($dirname."/".$file)) 

        { 

          echo 
$dirname."/".$file."<br>"

          
scan_dir($dirname."/".$file); 

        } 

      } 

    } 

    
// Закрываем директорию 

    
closedir($dir); 

  }
france@ вне форума Ответить с цитированием
Старый 11.01.2009, 09:58   #6
wall66
Участник клуба
 
Аватар для wall66
 
Регистрация: 04.10.2008
Сообщений: 1,485
По умолчанию

Цитата:
Сообщение от france@ Посмотреть сообщение
...
выкинь этот скриптик подальше и внимательно изучи все функции из второго поста в теме
свободен...
wall66 вне форума Ответить с цитированием
Старый 11.01.2009, 15:25   #7
mv28jam
Старожил
 
Аватар для mv28jam
 
Регистрация: 09.09.2008
Сообщений: 2,714
По умолчанию

этот скрипт заменяется функцией scandir, по крайней мере то что Вам надо точно
А лучше внимательно прочитайте, что написано выше, там всё что Вам надо есть.
Стрелок-охотник

Последний раз редактировалось mv28jam; 11.01.2009 в 15:27.
mv28jam вне форума Ответить с цитированием
Старый 09.02.2009, 20:18   #8
Loruoo18
Заблокирован
 
Регистрация: 31.01.2009
Сообщений: 5
Радость mortgage rate.

Finance market has drafted the scheme of unsecured loan for tenant, so MANY PEOPLE can also enjoy the facility of loan services.n order to attain unsecured loan for tenant, the borrower is simply required to be above 18 years of age and should be employed or self employed. WoW Gold.bad credit wow gold, holders who haveI maintained tagged credit file are allowed to apply for this unsecured loan. It can be stated that unsecured loan for tenant is basically designed for the suitability of tenants. Unsecured loan for tenant is are easily available with all banks, finance companies and money lending agencies. More and more tenants are taking the benefits of this loan plan because of its less complicated procedure and quick approval. Moreover, the loan is also free from any sort wow gold, of lender's restrictions. The loan amount retrieved through this provision can be utilized for any purpose according maple story powerleveling, most o the applicants follow the online application service as it is much faster and convenient to operate. There is no requirement of visiting lender's office. You can simply draft the application from your home, office or an Internet cafe. Moreover, every detailed information about the loan structure, pre requisites, and repayment term and loan amount is For new home buyers the first thing to consider is the home loans mortgage rates. It is important to try to get the best deal as possible as you will spend a long time paying for your dream house based on the agreed home loans mortgage rates. Before shopping for your dream home and checking out the different homes for sale, it is important to plan your budget way ahead. WoW Power Leveling.By doing this you can foresee what kind of mortgage payment that you can afford paying for a long tenure of time. Also it is a chance for you to narrow down your home choices to somewhat a few remaining but still great and affordable homes that will meet your budget.When you avail a mortgage home, you will then be charged with the existing home loansmaple story powerleveling, mortgage rates which the mortgage company or lender charges you for purchasing a house using their money. This will determine how much money you would shelve every month for paying them. Make sure the total amount will be within reach of your total monthly income or you will risk non payment and foreclosure of your home. Generally putting it this way that the higher the home loans mortgage rates, the higher the monthly mortgage payment you will have to pay.Home maple story powerleveling, loans mortgage rates changes all the time, like everyday and even by hour. Make sure that you lock on with a mortgage loan facilitator if you think that the mortgage rate they are offering are acceptable because if you don't and it increases the next day you risk paying for a bit higher mortgage rate.
Loruoo18 вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
дано два файла. получить третий,содержащий поочередно строки исходных двух файлов. HyvAchoK Паскаль, Turbo Pascal, PascalABC.NET 1 18.12.2008 10:51
Убрать пробелы из строки Neymexa Помощь студентам 2 09.12.2008 14:29
Убрать пробелы из строки Neymexa Общие вопросы по Java, Java SE, Kotlin 2 29.11.2008 11:03
Нужна помощь: выбор файлов исходя из имени файлов Antik163RUS Помощь студентам 4 19.06.2008 21:20
Как убрать перевод строки? Biowulf86 Помощь студентам 2 25.03.2008 11:05