• Register
0 votes
51 views

I was adding some php code inside a simple HTML page.

inserting a code snippet similar to the original one:

<html>
    <title> Page Title </title>
<body>
    <p> Paragraph contents </p>

<?php

//my php functions goes here

    <h3> some other html </h3>

?>
//second php block
<?php 
    for ($item = 5; ; $item++) {

        if ($item > 20) {
          break;
        }
        echo $item;
    }
?>

</body>
</html>

Does anyone know the possible reason of such a silly problem?

 

 

10 7 2
6,060 points

Please log in or register to answer this question.

1 Answer

0 votes

In my case I had to do some fixing on my closing php tags, such as Instead of writing

?>

write this

php ?>

->Mixing of PHP and HTML is slightly confusing so it is recommended to notice some differences between writing these also:

//wrong way

<? } ?> 

//right way

<?php ?>

 

-> short_open_tag on your php.ini file could be another reason of throwing that kind of error.

 set it to:

short_open_tag= On

The error "unexpected end of file" usually means you have a php code block that is not properly closed or somehow is not terminated yet. So the code is unable to be parsed anyway.

Another piece of code is still missing until end of file which is expected by the PHP compiler.

Hope that helps!

11 6 4
34,950 points

Related questions

0 votes
1 answer 20 views
20 views
This error continiously showing in my script. How to solve this error.
asked Oct 3, 2020 Daniel Anderson 4k points
0 votes
1 answer 24 views
24 views
Problem I am facing some strange behavior of PHP. I am new in PHP, but it are not my first lines in PHP. For some reason I am getting: Parse error: syntax error, unexpected end of file in the line Here is the adapted code: <html> <head> </head> <body> <?php function authenticate() ... Tally</a> <?php} else { echo "Wrong login details. Please try again"; } ?> <!-- HTML stuff --> </body> </html>
asked Dec 7, 2020 alexh 2.6k points
0 votes
1 answer 9 views
9 views
Problem: I'll make a submission for a response to my question. Please, I have searched the internet but have not found any useful material, and I am now having trouble continuing my studies.
asked Apr 1 rakib1 51.5k points
0 votes
1 answer 16 views
16 views
Problem: HELP! i need help understand this error parse error: syntax error, unexpected t_string in
asked Mar 12 Rohit kr 17.5k points
1 vote
1 answer 8 views
8 views
Problem : Any help is appreciated > PHP Parse error: syntax error, unexpected '{' in index.php on line 20
asked Apr 23 Abik Dey 4k points
0 votes
1 answer 114 views
114 views
Problem: Hello Kodlogs, I am working on a program that runs more on control expressions and I got a surprised error of this nature: syntax error, unexpected end-of-input, expecting keyword_end Can you help me out?
asked Nov 4, 2020 Festus James 380 points
0 votes
1 answer 8 views
8 views
problem: I am getting a problem of syntax error unexpected end expecting keyword_end ?
asked Apr 6 ashik 14.6k points
0 votes
1 answer 1 view
1 view
Problem: I got an error: Parse error: syntax error, unexpected end of file in the line
asked Apr 2 ummesalma 29.2k points
1 vote
1 answer 7 views
7 views
Problem: Any solution to this error? Syntax error unexpected keyword_ensure expecting keyword_end.
asked Apr 25 PkGuy 23.5k points
0 votes
1 answer 4 views
4 views
Problem: If you read the question above and understand the solution help me.
asked Apr 13 zayed1 58.7k points