Created
May 4, 2020 18:10
-
-
Save DanielSantoro/6bebdd6b512cadcba9d6b01b16d059e3 to your computer and use it in GitHub Desktop.
Random Generator - Pulls from CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
<div class="generator"> | |
<span class="generator-output"> | |
<?php | |
$sep=","; // separator | |
$project=file("https://example.com/csv/array.csv"); | |
$project_row=rand(0,count($project)-1); | |
$project_data=explode($sep,$project[$project_row]); | |
$project_num = count ($project_data); | |
for ($c=0; $c < $project_num; $c++) { | |
print $project_data[$c] . " "; | |
} | |
?> | |
</span><!-- end .generator-output --> | |
<span class="generator-button"> | |
<button class="btn btn-primary btn-lg" type="submit" name="refresh" value="Generate New" onclick="window.location.reload();">Generate New</button> | |
</span><!-- end generator-button --> | |
</div><!-- end .generator --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This quick bit of code pulls a random item from a CSV file with one column. All you'd need to do is change Line 7 to the static location of a .csv, or you can use a JavaScript array.
You can see it in use in a quick (and old) site here: http://tacnamegenerator.danielsantoro.com/