цикл исполняется только 1 раз, что не так???

N7
На сайте с 04.10.2010
Offline
16
852

Файл 1 :

<?php

for ($i=0; $i<10; $i++)

{

include "delstr.php";

include "razdel2.php";

include "gendat.php";

include "dopismain.php";

}

Файл delstr.php:

<?php

$num_stroka = 7; //Удалим 7 строку из файла

$file = file("gendat.php"); // Считываем весь файл в массив

for($i = 0; $i < sizeof($file); $i++)

if($i == $num_stroka) unset($file[$i]);

$fp = fopen("gendat.php", "w");

fputs($fp, implode("", $file));

fclose($fp);

?>

Файл razdel2.php:

<?php

$sl = file('ancorrzd.txt');

$sm = $sl[array_rand($sl, 1)];

$datam = $sm;

$file = fopen ("rzd.txt","w");

$str = "$datam";

fputs ( $file, $str);

fclose ($file);

$dataC = trim(file_get_contents ("rzd.txt"));

$data="\$dataCata='$dataC';";

$file = 'gendat.php';

$array=file( $file );

$array[7]= $data; //строка в которой нужно изменить значение $data

file_put_contents( $file, $array );

?>

Файл gendat.php:

<?php

error_reporting(E_ALL);

ini_set('display_errors', 'On');

ini_set('session.auto_start', '1');

//ini_set('upload_tmp_dir', 'c:\tmp');

set_time_limit(120);

@session_start();

$dataCata='xfgjcfyi';

$txtFile = 'result.txt'; // файл с текстом

$ancorFile = 'ancor.txt'; // файл с заголовками

$tplFile = 'template.txt'; // файл шаблона .dat файлов

$mainTplFile= 'maintemplate.txt'; // Шаблон файла со ссылками

$datDir = "articles/$dataCata"; // директория для .dat файлов

$datExt = 'dat'; // расширение .dat файлов

$mainFile = 'main.dat'; // Файл со ссылками на .dat файлы

$srcCharset = 'cp1251'; // Кодировка исходных файлов

$destCharset = 'cp1251'; // Кодировка файлов на выходе

$scriptCharset = 'utf-8'; // Кодировка скрипта

$blockLength = 4000; // Максимальный размер блока в байтах из файла с текстом

$file = fopen ("engine/menu.php","a");

$str = "<li><a href=\"/$dataCata/\">$dataCata</a></li>";

if ( !$file )

{

echo("Ошибка открытия файла");

}

else

{

fputs ( $file, $str);

}

fclose ($file);

if ($srcCharset == 'utf-8') $blockLength *= 2;

$blockLength = $blockLength % 2 > 0 ? $blockLength+1 : $blockLength;

if ( !is_dir($datDir) ) mkdir($datDir, 0777, true);

$hMain = NULL;

if ( !(@$hMain = fopen($mainFile, 'w+')) ) die("Невозможно создать файл $mainFile<br/>\b");

$hText = fopen($txtFile, 'r');

$ancors = explode("\n", $srcCharset == $scriptCharset ? file_get_contents($ancorFile) : iconv($srcCharset, $scriptCharset, file_get_contents($ancorFile)));

$template = $srcCharset == $scriptCharset ? file_get_contents($tplFile, 'r') : iconv( $srcCharset, $scriptCharset, file_get_contents($tplFile, 'r') ); // читаем шаблон

$content = '';

while ($content = fread($hText, $blockLength)) {

$fname = genName();

if (@$hDat = fopen("$datDir/$fname.$datExt", 'w')) {

$ancor = trim($ancors[rand(0, count($ancors)-1)]);

$content = $srcCharset == $scriptCharset ? trim($content) : iconv($srcCharset, $scriptCharset, trim($content));

// Генерим dat файлы по шаблону

$thisTpl = preg_replace("/(<!--.*?Kan_title.*?-->).*?(<!--.*?Kan_title.*?-->)/uism", "$1\n$ancor\n$2", $template);

$thisTpl = preg_replace("/(<!--.*?Kan_content.*?-->).*?(<!--.*?Kan_content.*?-->)/uism", "$1\n$content\n$2", $thisTpl);

$thisTpl = $scriptCharset == $destCharset ? $thisTpl : iconv( $scriptCharset, $destCharset, $thisTpl );

if (fwrite($hDat, $thisTpl)) {

echo "Файл $dataCata/$fname.$datExt записан<br/>\n";

$html = "

<loc><a href=\"/$dataCata/$fname.html\">$ancor</a></loc>\n";

fwrite($hMain, iconv($scriptCharset, $destCharset, $html));

} else { echo "Ошибка записи в файл $dataCata/$fname.$datExt<br/>\n"; }

} else {

echo "Не могу записать в файл $dataCata/$fname.$datExt<br/>\n";

}

}

// Генерация уникального имени

function genName() {

return substr(md5(uniqid(rand(), true)), 0, rand(7, 13));

}

?>

Файл dopismain.php:

<?

if (copy('main.dat', 'main0.dat'))

{ echo "Копирование успешно выполнено"; }

else

{ echo "Ошибка при копировании"; } // Скопировали маин дат, сохранили данные в маин 0

$file = fopen ("main.dat","w+");

$str = '<!-- Kan_title -->';

fputs ( $file, $str);

fclose ($file); // Вписали в пустой документ верх

$file = fopen ("main.dat","a");

$str = $dataCata; // Вписали переменную

fputs ( $file, $str);

fclose ($file);

$file = fopen ("main.dat","a");

$str = '<!-- Kan_title -->

<!-- Kan_content -->';

fputs ( $file, $str);

fclose ($file);

// Начинаем записывать линки в маин дат и текст

for ($i=0; $i<4; $i++)

{

include "genlink.php";

include "randstr.php";

}

$file = fopen ("main.dat","a"); //Дописываем конец файла

$str = '<br><!-- Kan_content -->

<!-- Kan_myinclude -->

main<!-- Kan_myinclude -->

<!-- Kan_description -->

<!-- Kan_description -->

<!-- Kan_keywords -->

<!-- Kan_keywords -->';

fputs ( $file, $str);

fclose ($file);

$source = 'main.dat';

$dest = "articles/$dataCata/main.dat";

if(!copy($source, $dest)) {

echo "Ошибка копирования файла $source...<br />\n";

}

?>

I
На сайте с 29.04.2006
Offline
135
#1
for ($i=0; $i<10; $i++)
{
include "delstr.php";
include "razdel2.php";
include "gendat.php";
include "dopismain.php";
}
Файл delstr.php:

дальше даже смотреть не хочется...

Sergey Gr.
На сайте с 21.10.2008
Offline
48
#2

Очевидно потому, что переменная $i используется в двух других файлах.

Вместо благодарности, разместите свой код на сервисе govnokod.ru)

N7
На сайте с 04.10.2010
Offline
16
#3
ipconfig:
дальше даже смотреть не хочется...

Что не так??

Hartamon
На сайте с 04.07.2006
Offline
165
#4

ТС, погуглите, что такое функции в программировании, и после этого перепишите код по-человечески.

Ord
На сайте с 15.11.2005
Offline
175
Ord
#5

С таким кодом вам на http://www.govnokod.ru

Создаем лучший кулинарный проект, iamcook.ru
[Удален]
#6

Можно я помогу? http://govnokod.ru/7232

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий