0

I have been attempting to write a website that processes names of people and reads them back in a list, so I can do other things with them later. I need them to be alphabetized, and show up with each person on their own line. Kind of like this:

[1] Doe--John

[2] Washington--George

[3] Zekeman--William

I have created a php script that uses an array to sort the names; it is in the file sort.php. I have created a file for the people, called students.html. These names were fed in from a form.

To display the name on the webpage, I created a simple php include function.

Here is my coding:

Sort.php

    <?php

        $filename = "students.html"

        $names = array file( string $filename );
        sort($names);
        foreach ($names as $key => $val) {
              echo "[" . $key . "] " . $val . "\n";
        }

    ?>

Students.html

    "Washington--George",
    "Zekeman--William",
    "Doe--John",

Webpage

   <?php include 'sort.php';?>

Everything works perfectly, except the webpage displays this error:

Parse error: syntax error, unexpected T_STRING, expecting '(' in /home/www/the/path/to/my/directory/sort.php on line 3

I have played with it and I cannot figure out how to fix the error. Any assistance would be greatly appreciated!

Note: I apologize if this makes no sense. I am brand new to this.

2
  • did you check your code properly ?? i think u are missing semicolon in you code?? Commented Jun 2, 2014 at 12:27
  • 1
    missing ";" in first line after closing "". Commented Jun 2, 2014 at 12:27

3 Answers 3

4

On the end of $filename = "students.html" you need to put a ;

Edit: also $names = file($filename);

Sign up to request clarification or add additional context in comments.

Comments

4
$names = array file( string $filename );

This is wrong. You need to remove both array and string.

2 Comments

And he also miss a ; on the previous line.
Right, I saw after posting my comment.
1

should be

<?php

$filename = "students.html";

$names = file( $filename );
sort($names);
foreach ($names as $key => $val) {
    echo "[" . $key . "] " . $val . "\n";
}

?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.