Ramy Al Zuhouri
Ramy Al Zuhouri

Reputation: 21966

Page not load while trying to read a file

I need to read a file located in the localhost path whose strings are separated by ";". I am trying to define a function, the function should open the file, read a single string and put it in the second argument passed.
But from the validator I get a parse error:
Fatal error: Cannot redeclare readfile() in your code on line 13

<?php                                     
function readfile($filename, $var)
{
    $file=fopen($filename,"r");
    while($temp!=";")
    {
        $temp=fread($file,1);
        if($temp!=";")
            $result=$result . $temp;
    }
    fclose($file);
    $var=$result;
}
$filename="log.txt";
readfile($filename,$nome);
echo $nome;
?>

What is wrong in this code?

Upvotes: 2

Views: 104

Answers (2)

Menztrual
Menztrual

Reputation: 41587

readfile is a built in php function

http://php.net/manual/en/function.readfile.php

Name it to something different

Upvotes: 3

HappyTimeGopher
HappyTimeGopher

Reputation: 1387

The error you got is telling you that you've got another function called"readfile" somewhere earlier in your code.

Either find and remove the other version, or change this function name to something like "read_file".

--- edit ---

It's because PHP already has a function called readfile :)

Change the function name and you'll be good to go.

Upvotes: 2

Related Questions