n00bl3t321 n00bl3t321 - 6 months ago 11
PHP Question

how to generate a random string + text + multiple lines

I actually got this script from here... but it is not quite what I needed...

<?php
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}

// Echo the random string.
// Optionally, you can give it a desired string length.
<?php echo generateRandomString(); ?>
?>


basically, I wanted this small php script to generate thousands of lines (~3000)...

in this format:

mytext/(the_random_string_here)
mytext/(the_random_string_here)
mytext/(the_random_string_here)
mytext/(the_random_string_here)
mytext/(the_random_string_here)


up to the very end (~3000 lines) with each line have a random string...

Answer

you can use a for loop to generate it 3000 times

for($i = 0; $i < 3000; $i++){
    echo 'mytext/'.generateRandomString().'<br>';
}

The answer was inside your code snippet that you provided