. */ date_default_timezone_set('Europe/Paris'); function random_pronounceable_word($l = 'en', $length = 4 ) { // return a $length long word in the language of code $l // Inspired from: // Generate Random Pronouceable Words // http://planetozh.com/blog/2012/10/generate-random-pronouceable-words/ global $cons_can_start_and_end, $cons_cant_end, $cons_cant_start, $vows; // Get all cons characters except those witch cannot start $cons1 = array_merge($cons_can_start_and_end[$l], $cons_cant_end[$l]); // Get all cons characters $cons2 = array_merge($cons1, $cons_cant_start[$l]); // Get all cons characters exept those witch cannot end $cons3 = array_merge($cons_cant_start[$l], $cons_can_start_and_end[$l]); $word = ''; $candidate = ''; // Randomly decide if start by vowel ? $curent_type_is_vow = (bool)mt_rand(0, 1); // Get a random word that match the desired character number while( iconv_strlen($word,'UTF-8') != $length ) { // Randomly get a candidate char to concatenate if( $curent_type_is_vow ) { // Candidate is a vowel $candidate = $vows[$l][ mt_rand(0, count( $vows[$l] ) -1) ]; } else { // Candidate is a cons that should not start if( iconv_strlen($word,'UTF-8') == 0 ) { $candidate = $cons1[ mt_rand(0, count($cons1) -1) ]; } else { // Candidate is a cons that can start // First, try with any cons $candidate = $cons2[ mt_rand(0, count($cons2) -1) ]; if(iconv_strlen($word.$candidate,'UTF-8') >= $length) { // If it would end the word, try with a candidate char that should not end $candidate = $cons3[ mt_rand(0, count($cons3) -1) ]; } } } // Evaluate the candidate character and add to the word if( (iconv_strlen($word.$candidate,'UTF-8') <= $length) && (substr($word, -strlen($candidate)) != $candidate ) ) { // Not to long and not the redundant pattern of latest char, // so concatenate the candidate char to the word $word.= $candidate; // Alternate sounds for next iteration $curent_type_is_vow = ( $curent_type_is_vow === false ); } } return $word; } function send_source($file) { header('Cache-Control: public'); header('Pragma: public'); header('Content-Type:text/plain; charset=UTF-8'); header('Content-Length: '.filesize($file)); readfile($file); } // Variables $display = array( 'language' => array( 'fr' => 'Langue', 'en' => 'Language', ), 'available_in_langs' => array( 'fr' => 'en français et en anglais', 'en' => 'in english and french', ), 'provided_by' => array( 'fr' => 'Fourni par', 'en' => 'Provided by', ), 'backlink' => array( 'fr' => 'Lien vers cette page', 'en' => 'Link to this page', ), 'colon' => array( 'fr' => ' :', 'en' => ':', ), 'semicolon' => array( 'fr' => ' ;', 'en' => ';', ), 'redo' => array( 'fr' => 'Recalculer', 'en' => 'Redo', ), 'page_title' => array( 'fr' => 'Générateur aléatoire de mots prononçables', 'en' => 'Random pronounceable words generator', ), 'source_code' => array( 'fr' => 'Code source', 'en' => 'Source code', ), 'output_raw' => array( 'fr' => 'Format texte', 'en' => 'Text format', ), 'output_json' => array( 'fr' => 'Format json', 'en' => 'Json format', ), 'generated_in' => array( 'fr' => 'Liste de mots générée en', 'en' => 'Word list generated in', ), 'char_count' => array( 'fr' => 'caractères', 'en' => 'characters', ), 'words_per_line' => array( 'fr' => 'mot(s) par ligne', 'en' => 'word(s) per line', ), 'lines' => array( 'fr' => 'lignes', 'en' => 'lines', ), ); // Consonant sounds exclusing those wich cannot start nor end a word $cons_can_start_and_end = array( 'fr' => array( // single consonants. Beware of Q, it's often awkward in words 'c', 'd', 'f', 'k', 'l', 'm', 'n', 'r', 's', 't', 'x', 'z', // possible combinations excluding those which cannot start nor end a word 'pt', 'ps', 'st', ), 'en' => array( // single consonants. Beware of Q, it's often awkward in words 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'z', // possible combinations excluding those which cannot start a word 'pt', 'gl', 'gr', 'ch', 'ph', 'ps', 'sh', 'st', 'th', 'wh', ) ); // consonant combinations that cannot start a word $cons_cant_start = array( 'fr' => array( 'll', 'nn', 'pp', 'ss', 'tt', ), 'en' => array( 'ck', 'cm', 'dr', 'ds', 'ft', 'gh', 'gn', 'kr', 'ks', 'ls', 'lt', 'lr', 'mp', 'mt', 'ms', 'ng', 'ns', 'rd', 'rg', 'rs', 'rt', 'ss', 'ts', 'tch', ) ); // consonnant combinations that cannot end a word $cons_cant_end = array( 'fr' => array( 'b', 'g', 'h', 'j', 'p', 'v', 'w', // possible combinations which cannot end a word 'gl', 'gr', 'ch', 'ph', 'qu', 'th', 'gn', ), 'en' => array( ) ); // wovels $vows = array( 'fr' => array( // single vowels 'a', 'e', 'é', 'è', 'i', 'o', 'u', 'y', // vowel combinations your language allows 'ae', 'ai', 'alla', 'allaé', 'allaè', 'allai', 'allau', 'alle', 'allé', 'allè', 'alli', 'allia', 'allie', 'allié', 'alliè', 'allio', 'alliou', 'alliu', 'allo', 'alloa', 'alloe', 'alloé', 'alloè', 'allou', 'allu', 'allui', 'alluo', 'ao', 'au', 'aou', 'aya', 'aye', 'ayi', 'ayo', 'ayu', 'ia', 'ie', 'iè', 'ié', 'io', 'iou', 'iu', 'oe', 'oi', 'ou', 'oya', 'oye', 'oyé', 'oyè', 'oyo', 'oyu', 'ya', 'yaou', ), 'en' => array( // single vowels 'a', 'e', 'i', 'o', 'u', 'y', // vowel combinations your language allows 'ee', 'oa', 'oo', ) ); $provider_name = 'ordi49.fr'; $provider_url = 'http://ordi49.fr/'; // Get the query strings // Gess the lang $default_lang = 'fr'; $browser_lang = array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2) : $default_lang; if ( array_key_exists($browser_lang, $display['language']) ) $default_lang = $browser_lang; $lang = empty($_GET['lang']) ? $default_lang : $_GET['lang']; $lang = array_key_exists($lang, $display['language']) ? $lang : $default_lang; $default_lines = 30; $lines_min = 1; $lines_max = 1000; $lines = (array_key_exists('lines', $_GET)) ? $_GET['lines'] : $default_lines; $lines = ( is_numeric($lines) && ($lines>=$lines_min) && ($lines<=$lines_max) ) ? $lines : $default_lines; $default_words_per_line = 1; $words_per_line_min = 1; $words_per_line_max = 10; $words_per_line = (array_key_exists('words_per_line', $_GET)) ? $_GET['words_per_line'] : $default_words_per_line; $words_per_line = ( is_numeric($words_per_line) && ($words_per_line>=$words_per_line_min) && ($words_per_line<=$words_per_line_max) ) ? $words_per_line : $default_words_per_line; $default_char_count = 0; $char_count_min = 3; $char_count_max = 12; $char_count = (array_key_exists('char_count', $_GET)) ? $_GET['char_count'] : $default_char_count; if(is_numeric($char_count)) { $char_count = ( ($char_count==0) || (($char_count>=$char_count_min) && ($char_count<=$char_count_max)) ) ? $char_count : $default_char_count; } else $char_count = $default_char_count; $char_count_txt = ($char_count==0) ? 'x' : $char_count; // Proceed if(array_key_exists('content', $_GET)) { // Output its own php source if($_GET['content'] == 'source') { send_source(__FILE__); exit; } // Output in raw text if($_GET['content'] == 'txt') { header("Content-Type: text/plain; charset=UTF-8"); for ($line_nr = 1; $line_nr <= $lines; $line_nr++) { for ($word_nr = 1; $word_nr <= $words_per_line; $word_nr++) { if($char_count==0) echo (random_pronounceable_word($lang, mt_rand($char_count_min, $char_count_max)) ); else echo (random_pronounceable_word($lang, $char_count) ); if( ( $word_nr != $words_per_line ) && ( $words_per_line > 1 ) ) echo (' '); } echo "\n"; } exit; } // Output in json format if($_GET['content'] == 'json') { header("Content-Type: application/json; charset=UTF-8"); header("Access-Control-Allow-Origin: *"); /* Allow cross domain request (XHR) */ $output_array = array(); for ($line_nr = 1; $line_nr <= $lines; $line_nr++) { for ($word_nr = 1; $word_nr <= $words_per_line; $word_nr++) { if($char_count==0) $output_array[] = random_pronounceable_word($lang, mt_rand($char_count_min, $char_count_max)); else $output_array[] = random_pronounceable_word($lang, $char_count); } } echo(json_encode($output_array)); exit; } } $randomize_duration = microtime(true); $result = array(); for ($line_nr = 1; $line_nr <= $lines; $line_nr++) { for ($word_nr = 1; $word_nr <= $words_per_line; $word_nr++) { if($char_count==0) $result[$line_nr][$word_nr] = random_pronounceable_word($lang, mt_rand($char_count_min, $char_count_max)); else $result[$line_nr][$word_nr] = random_pronounceable_word($lang, $char_count); } } $randomize_duration = (microtime(true) - $randomize_duration); header('Expires: 0'); header('Cache-Control: private, max-age=0, no-cache'); header('Pragma: no-cache'); header('Content-Type: text/html; charset=UTF-8'); ?> <?php echo $display['page_title'][$lang]; ?>


  •   • 

'.$provider_name.' • '; echo '© '.date("Y").' • '; echo ''.$display['backlink'][$lang].' • '; echo ' '.$display['output_raw'][$lang].' • '; echo ' '.$display['output_json'][$lang].' • '; echo ''.$display['source_code'][$lang].''; // For robot indexation: foreach ($display['language'] as $l => $v){ if($l!=$lang) echo ''; } echo '
'."\n"; ?>


$wordlist){ foreach ($wordlist as $word_nr => $word){ echo ($word); if( ( $word_nr != $words_per_line ) && ( $words_per_line > 1 ) ) echo (' '); } echo "
\n"; } ?>