I wanted to have a quick an easy way to get a random name, from say a list of D&D monsters.
But I wanted the script to be accessible from anywhere on the network.
So I wrote this simple PHP script and put it on a web server.
create a new php file.
paste this array into the file, inside the usual php tags.
$filename = "names.txt";
$names = file($filename, FILE_IGNORE_NEW_LINES);
$num = random_int(0,303);
print ($names[$num]);
create another file, called names.txt that contains the list of monster names.
Change the 303 to the number of items in your list, minus 1
see demo HERE
PHP Script to return random D&D Monster name
by
Leave a Reply