简体   繁体   中英

Syntax error: Unexpected '/' error

I'm using fopen() but I get this error on execution.

Parse error: syntax error, unexpected '/' in /home/furtherpath.. on line 7

The line 7 is:

/home/a11*****/public_html/rishi/rishi_someone_php.php = fopen("rishi_someone_php.php","r");

I know I should place a file handler instead but that also doesn't seem to work and gives the same error. Can't figure out why.

What I'm doing is creating a html page using php.:

$html="<html> \n <head> \n <title>".$fn."</title> \n </head> \n <body> \n <?php \n $file=fopen('".$full."','r'); \n while(!(feof($file))) \n { \n echo htmlspecialchars(fgets($file)).'<br/>'; \n } \n fclose($file); \n ?> \n </body> \n </html>";

Thanks in advance.

Here is a cleaned up version of your script. Try to understand it. I'e combined the string at each html element just to be clear. There is no reason for php tags within php tags. In your code at this line $file=fopen('".$full."','r');

You are trying to quote a variable of type string. That is not necessary with variables. PHP will know that it is a string, so don't do that. Only use quotes when a string literal is being passed into the function as an arguments.

$html = "<html>\n<head><title>". $fn."</title>\n</head><body>\n";

$fp = fopen($full, "r");
if ($fp) {
    while (($line = fgets($fp)) !== false) {
        $html .= htmlspecialchars($line, ENT_QUOTES, 'UTF-8');
        $html .= "<br />";
    }
} else {
    $html .= "No data";
    $html .=  "<br />";
} 

fclose($fp);

$html .= "</body>\n</html>\n";

echo $html;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM