Skip to content

Instantly share code, notes, and snippets.

@LucaTNT
Created November 13, 2012 21:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LucaTNT/4068569 to your computer and use it in GitHub Desktop.
Save LucaTNT/4068569 to your computer and use it in GitHub Desktop.
Generatore di frasi casuali
<?php
/* Casual Text
* Autore: Luca Zorzi
* Data: 13/11/2012 (originariamente risale circa al 2004-2005)
* Licenza: BSD
* Scopo: nessuno
* Funzionamento: inserire 4 file txt nella stessa cartella in cui risede questo script:
* nomi.txt dovrà contenere dei nomi, singolari
* verbi.txt dovrà contenere dei verbi TRANSITIVI, non vogliamo frasi come pisciare il cane oppure salire le valigie
* complementi.txt dovrà contenere dei complementi oggetti, che saranno generalmente altri nomi
* conginuzioni.txt dovrà contenere delle congiunzioni per unire le geniali frasi che ne usciranno
*/
$numeroFrasi = 100; // Inserire qui il numero di frasi
header('Content-Type: text/html; charset=utf-8');
$nomi = explode("\n", file_get_contents('nomi.txt'));
$verbi = explode("\n", file_get_contents('verbi.txt'));
$complementi = explode("\n", file_get_contents('complementi.txt'));
$congiunzioni = explode("\n", file_get_contents('congiunzioni.txt'));
$totNomi = count($nomi);
$totVerbi = count($verbi);
$totComplementi = count($complementi);
$totConiugazioni = count($congiunzioni);
for($i = 0; $i <= $numeroFrasi; $i++){
$randNome = rand(0, $totNomi - 1);
$randVerbo = rand(0, $totVerbi - 1);
$randComplemento = rand(0, $totComplementi - 1);
$randCongiunzioni = rand(0, $totConiugazioni - 1);
$frase = $nomi[$randNome].' '.$verbi[$randVerbo].' '.$complementi[$randComplemento];
if($i != $numeroFrasi){
$frase .= ' '.$congiunzioni[$randCongiunzioni];
}
echo $frase."<br />\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment