Code: Select all
<?
require_once('engine.php');
for($a = 1;$a != 6;$a++) {
echo "\t\t\t<li>" . $name . "</li>";
}
?>How can I do that?
Moderator: General Moderators
Code: Select all
<?
require_once('engine.php');
for($a = 1;$a != 6;$a++) {
echo "\t\t\t<li>" . $name . "</li>";
}
?>Code: Select all
<?
for($a = 1;$a != 6;$a++) {
require('engine.php');
echo "\t\t\t<li>" . $name . "</li>";
}
?>Code: Select all
<? // Name randomizer engine, using specially formatted documents to define the name structure and a PHP parser to randomize names from that structure.
// We open the file for reading...
$file = fopen($namefile, "r") or exit("Unable to open file!");
// ... and put everything in the file in arrays. This loop is run on each line until the end of the file.
while(!feof($file)) {
// We go to the next line (or the first line, if run for the first time).
$nextline = fgets($file);
// Anything after two slashes is removed, as are empty lines and beginning and trailing whitespaces.
$nextline = preg_replace("/\/\/.+|(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "", $nextline);
$nextline = preg_replace("/^[ \t]+|[ \t]+$|\n$/", "", $nextline);
// If, after this, the line is not empty...
if ($nextline != "") {
// ... we check to see if it's a pattern (begins with a dot). If it is, it's put into the pattern array.
if (preg_match('/^\./',$nextline)) {
$pattitle = preg_replace('/^\./','',$nextline);
$pattitle = preg_replace('/(?= ).*/','',$pattitle);
$nextline = preg_replace('/^[^\n|^ ]*(?= )/','',$nextline);
$nextline = preg_replace('/^ /','',$nextline);
$patterns[$pattitle] = $nextline;
} else {
// If it's not a pattern, we check to see of it's a section header...
if (preg_match('/^\[.*/',$nextline)) {
$nextline = preg_replace('/^\[/','',$nextline);
$nextline = preg_replace('/\]$/','',$nextline);
$sectline = $nextline;
// ... or else we put it in an appropriate place in the array.
} else {
if ($nextline != "") {
$elements[$sectline][] = $nextline;
}
}
}
}
}
// When it's all over, we close the file. We won't be needing it anymore.
fclose($file);
// Let's randomly select a pattern.
$thepattern = array_rand($patterns);
$thepattern = $patterns[$thepattern];
// This function does the substituting.
function randel($anelement) {
global $elements; // We need this global.
$anelement = preg_replace("/\{|\}/","",$anelement); // We strip away the curly brackets.
$anelement = implode($anelement); // It needs to be a string, not an array.
$anelement2 = count($elements[$anelement], COUNT_RECURSIVE) - 1; // Since array_rand() can't be used on multi-dimensional arrays, we count the number of values in the selected sub-array, ...
$anelement2 = rand(0,$anelement2); // ... randomly choose a number ...
$theelement = $elements[$anelement][$anelement2]; // ... and then call the sub array.
return $theelement;
}
// Now we print out the pattern, substituting any stuff in curly brackets with a random entry from the list of elements.
$name = preg_replace_callback('/\{[^\{\}\r\n]*\}/','randel',$thepattern);
?>