[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: Помогите изменить формат вывода случайной строки
IgorG
Здравствуйте Други!
Прошу помочь в решении проблемы.
Знания поверхностные и поэтому использовал всю свою скудную "библиотеку" так и не смог найти решение.
Имеется функция вывода случайной строки из файла:

function RandLine($num,$s,$fileName){
$data = file($fileName);
$arr = array();
$output = "";


for ( $i = 0; $i < $num; $i++ ) {

do {
$rand = mt_rand(0, count($data) - 1);
} while ( in_array($rand, $arr) );

$arr[] = $rand;
$output .= str_replace("\n", "", $data[$rand]).$s;
}
return $output;
}
****************Изменить этот кусок кода********************
function GenTheText( $t ) {
while ( preg_match( '#\{([^\{\}]+)\}#i', $t, $m ) ) {
$v = explode( '|', $m[1] );
$i = rand( 0, count( $v ) - 1 );
$t = preg_replace( '#'.preg_quote($m[0]).'#i', $v[$i], $t, 1 );
} return $t;
}
$str='';
***********************************************************

function mb_ucfirst($str) {
return mb_substr(mb_strtoupper($str,'utf-8'),0,1,'utf-8').mb_strtolower(mb_substr($str,1,mb_strlen($str,'utf-8'),'utf-8'),'utf-8');
}


$public = RandLine($num = 1,$s = "", $dir."public.txt");
$attach = "img/".$public.".txt";
$rand36 = rand(1,1);
$attachments = RandLine($num = $rand36,$s = ", ", $attach);
$randtext = file_get_contents($dir."text/".$public.".txt");

$text = GenTheText($randtext);

echo $public."<br/>".$attach."<br/>".$attachments."<br/>".$text;
$ch = curl_init('https://api.vk.com/method/wall.post');
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3');
curl_setopt ($ch, CURLOPT_REFERER, 'https://api.vk.com/method/wall.post');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $dir.'cookie.txt');
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'owner_id=-'.$public.'&v=5.28&access_token='.$access_token.'&attachments='.$attachments.'&message='.$text);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_HTTPHEADER, array('Expect:'));
curl_exec ($ch);
$result = curl_multi_getcontent ($ch);
echo "\n".'Login OK'."\n".'[result ===8<===>'."\n".$result."\n".'<===>8=== result]'."<br/>\n";
echo "http://vk.com/public".$public."";
curl_close ($ch);

?>

Но эта функция имеет недостаток по ограничению количества символов в 30 тыс.
Пример:
{привет|здравствуй|как дела|.....}-30 тыс.
При добавлении вариантов слов или словосочетаний приходит ответ:
Compilation failed: regular expression is too large at offset 291712 in C:\OpenServer\OSPanel\domains\ut316\send.php on line 31
Если возможность уйти от формата {|} и перейти на формат:
текст1
текст2
текст3
.....
Необходимо брать случайную текстовую строку из файла объемом хотя бы 1 мб
Текствый файл находиться в папке text

Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.