Male name generated: Jeff Hardwood
Female name generated: Rachel Divorceman

Click to get new names

Code:

<html>
<head>
<title>PHP TEST YAHHH</title>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body>

<div class="topbar">
<?php
include 'navbar.php';
?>
</div>

<?php
    
    // name generator
    // same as 046, but pulls names from a text file
    // uses a random number to pull names from generated arrays



    function roll ($min, $max)
    {
        
        return mt_rand($min, $max);
        
    }
    
    $male = file ('male.txt');
    $female = file ('female.txt');
    $last = file ('last.txt');
    
    $mLength = count($male) - 1;
    $fLength = count($female) - 1;
    $lLength = count($last) - 1;
    
    $mRoll = roll(0, $mLength);
    $fRoll = roll(0, $fLength);
    $lRoll = roll(0, $lLength);

    echo "Male name generated: ";
    echo $male[$mRoll];
    echo " ";
    echo $last[$lRoll];
    echo '<br>';
    
    $lRoll = roll(0, $lLength);
    
    echo "Female name generated: ";
    echo $female[$fRoll];
    echo " ";
    echo $last[$lRoll];
    echo '<br>';
    
    
    echo '<br>';
    
?>

<a href="javascript:history.go(0)">Click to get new names</a>

<div class="codebox">
<h3>Code:</h3>
<?php
highlight_file("ex047.php");
?>
</div>

</body>
</html>