Skip to content

Instantly share code, notes, and snippets.

@DanielSantoro
Created May 4, 2020 18:10
Show Gist options
  • Save DanielSantoro/6bebdd6b512cadcba9d6b01b16d059e3 to your computer and use it in GitHub Desktop.
Save DanielSantoro/6bebdd6b512cadcba9d6b01b16d059e3 to your computer and use it in GitHub Desktop.
Random Generator - Pulls from CSV
<?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 -->
@DanielSantoro
Copy link
Author

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment