Reputation: 79
Hi there i have some questions, how to continuing the data while the condition has reach 500 value on the new file and then create some random number beside the sitemap name. this is my script:
$rand = rand(1,9);
$open1 = fopen("sitemap-$rand.txt", 'w');
$web = 'http://'.$_SERVER['SERVER_NAME'].'/';
$ws = $_SERVER['SERVER_NAME'];
$i = 1;
foreach ($data as $key => $value) {
$hasil = home_base_url().strtolower($value).'.html'."\n";
fwrite($open1, $hasil);
if (++$i == 500) {
break;
}
}
Thanks for your help
Upvotes: 0
Views: 49
Reputation: 16113
You mean that there are 500 lines, per random numbered sitemap?
if (++$i == 500) {
$value = rand(0,9);// set valuie to a new random value
$i = 0; // reset the counter
}
N.B.: It might be that the loop will pick the same random number twice. Either pick a larger number to decrease the odds, or create a small function which knows which names are used, so you must pick a new name.
Upvotes: 1