lundi 29 décembre 2014

PHP semi-random word generator

The following code is working. But I'd like to improve it. Basically, this page displays a random str per each categories and reloads a page when a user pushes a button. Can it be different so I could manage the data easier(I want to update the words library frequently). I also wonder if this is short enough for quick loading. Thank you so much for your help in advance.



<!-- begin -->
<html>
<head>
</head>

<body>


<?php
#hash = random url generated from 128 chars


$words = array('apple', 'orange', 'banana');
$rword = rand(0,2);

$syms = array('chair', 'sofa', 'table', 'coffee table');
$rsym = rand(0,3);

$value1 = $words[$rword];
$final1 = strtoupper($value1);

$value2 = $syms[$rsym];
$final2 = strtoupper($value2);

?>


<h2>Fruit</h2><p><?php echo $final1 = strtolower($value1); ?></p>
<h2>Furniture</h2><p><?php echo $final2 = strtolower($value2); ?></p>


<FORM METHOD="LINK" ACTION="random.php">
<INPUT TYPE="submit" VALUE="generate again">
</FORM>



</body>
</html>

<!-- end -->




Aucun commentaire:

Enregistrer un commentaire