View Full Version : PHP Help


Coconut99
07-02-2003, 06:37 PM
I'm trying to make a name generator using PHP with two parts: the name and an adjective. Whenever I try to display the results with echo(), I get parse errors. This is my code so far:

<?
//GET ARRAYS
$name_array = file("names.txt");
$adj_array = file("adjs.txt");
//SET VARS
$random_name = array_rand ($name_array, 1);
$random_adj = array_rand ($adj_array, 1);
?>

When I run this, I get no errors but nothing else, either. (The above code could be wrong, anyway.) How should/can I display the finished product? Thanks in advance!

Edit: For instance, when I try:

<?
echo("$random_name $random_adj");
?>

I get: Parse error: parse error, unexpected ';' in /home/virtual/site140/fst/var/www/html/php/goblins3.php on line 9.

Coconut99
07-02-2003, 06:46 PM
Aha! I accidently switched the close parenthesis and the semicolon. So now I don't have a parse error but I have:
7 random_adj
It's supposed to have text strings, not numbers, and the random_adj is supposed to be a string that holds a word from the adj.txt file, not random_adj. Anybody know how to fix this? Thanks again!

Coconut99
07-02-2003, 09:00 PM
Okay, here is my updated code, which works:

<?
//GET ARRAYS
$name_array = file("names.txt");
$adj_array = file("adjs.txt");
//SET VARS
$random_name=array_rand ($name_array, 1);
$random_adj=array_rand ($adj_array, 1);
?>
<? echo("$random_name"); ?><BR>
<? echo("$random_adj"); ?>

A brief explanation of what this is supposed to do: I have two files with 25 names in one and 25 adjectives in another. The script opens the files and makes them arrays, and then randomly picks one of the names/adjectives to display together. BUT it shows a number between 0 and 25 instead of text. How do I get it to show text, not numbers? Thanks!!

Coconut99
07-02-2003, 09:31 PM
*does a happy dance* Yay! I got it to work! A mod can lock this topic now. :)