array_slice无法按预期工作

时间:2015-04-20 14:47:53

标签: php

我正在尝试使用当前随机域和随机域的标题构建一个随机域生成器但是我对逻辑有一些问题所以建立了以下脚本并且当前输出是:

file.txt - CURRENT OUTPUT

# SomeTitleText
staffweb.hawthorn73.org on 2014-05-11
domain:
sunshineny.com    
# SomeTitleText
staffweb.hawthorn73.org on 2014-05-11
text:
sunshineny.com
text:
appsmylife.com
 . 
 .
 and goes like this and includes all the urls

预期输出

# SomeTitleText first 10-20 domains separated by comma(random number of domains) on 
2014-05-11
text: sunshineny.com
text: appsmylife.com
 .
 .
// next 8/9/10/..20 domains (random between 10-20)
# SomeTitleText next 10-20 domains separated by comma (random number of domains) on 
2014-05-12
text: next **REMAINING** domains after the random domain and again random number of domains 
between 10-20 and stop if it finished all domains

剧本:

function createDateRangeArray($strDateFrom,$strDateTo) {
    $aryRange=array();
    $iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2),     substr($strDateFrom,8,2),substr($strDateFrom,0,4));
    $iDateTo=mktime(1,0,0,substr($strDateTo,5,2),     substr($strDateTo,8,2),substr($strDateTo,0,4));
    if ($iDateTo>=$iDateFrom)
    {
        array_push($aryRange,date('Y-m-d',$iDateFrom)); // first entry
        while ($iDateFrom<$iDateTo)
        {
            $iDateFrom+=86400; // add 24 hours
            array_push($aryRange,date('Y-m-d',$iDateFrom));
        }
    }
    return $aryRange;
}
$urls1 = array(
    'http://samsung.gamechodt.com',
    'https://sunshineny.com',
    'http://www.appsmylife.com',
    'http://greenfirefarms.com',
    'http://gillesarbeau.com',
    'https://www.digitalpoint.com',
    'http://www.besttravel.com',
    'http://faceshapes101.wordpress.com',
    'http://www.exploteam.pl',
    'http://www.graficon.es',
    'http://shafatrasool.com',
    'http://xvnp.com',
    'http://en.seokicks.de',
    'http://nokia-2610.gamechodt.com',
    'http://ziiquam.606h.net',
    'http://www.hoyenfutbol.com',
    'http://doggoodsusa.com',
    'http://www.blackpaper.ch',
    'http://www.teflzorritos.com',
    'http://abovegravityonline.com',
    'http://staffweb.hawthorn73.org'
);
$domains = array();
foreach ($urls1 as $domain) {
    $domain = str_replace('http://www.', '', $domain);
    $domain = str_replace('http://', '', $domain);
    $domain = str_replace('https://www.', '', $domain);
    $domain = str_replace('https://', '', $domain);
    array_push($domains, $domain);
}
$file = fopen('disavow.txt', "w");
$i = 0;
$date_range = createDateRangeArray('2014-05-10','2015-04-10');
$text = '';
$domains_bad = array();
foreach ($urls1 as $bad_domain) {
    $i++;
    $random = range(10,20);
    shuffle($random);
    $range = range(1, count($urls1), $random[0]);
    if ($i <= count($urls1)) {
        $range_domain = $i + $range[$i];
    } else {
        break;
    }
    $bad_domain_range_array = array_slice($domains, $range_domain);
    $bad_domain_range = implode(', ', $bad_domain_range_array);
    if($i == $range[0]) {
        $domaintext = "# SomeTitleText $bad_domain_range on $date_range[$i] ".PHP_EOL;
        $text .= PHP_EOL.$domaintext.PHP_EOL;
        $text .= "text:".$domains[$i].PHP_EOL;
        unset($domains[$i]);
    } else {
        $text .= "text:".$domains[$i].PHP_EOL;
        unset($domains[$i]);
    }
    fwrite($file, $text);
}

0 个答案:

没有答案