Click here to Skip to main content
15,899,126 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sorry i know this is a basic question, but i have been trying for hours and i can't seem to think what is wrong with this.

HTML
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php echo "<p>Hello World!</p><br>";?>
</body>
</html>


the output gives.

My first PHP page
Hello World!
";?>


why ';?> appears.

What I have tried:

<!DOCTYPE html>
    <html>
    <body>
    <h1>My first PHP page</h1>
    <?php echo <p>Hello World!</p><br>
    </body>
    </html>


gives output correctly,but it seems that syntax is wrong according to w3schools.
Posted
Updated 3-Jan-18 17:03pm
Comments
Member 13605837 4-Jan-18 6:30am    
ok,but why echo output ;?> symbols
EZW 9-Jan-18 1:53am    
Is this in a PHP file format and run on a PHP enabled server?
Member 13605837 10-Jan-18 3:41am    
yes

1 solution

Quoting from the PHP manual,
echo — Output one or more strings

Description

void echo ( string $arg1 [, string $... ] )
Outputs all parameters. No additional newline is appended.

echo is not actually a function (it is a language construct), so you are not required to use parentheses with it. echo (unlike some other language constructs) does not behave like a function, so it cannot always be used in the context of a function. Additionally, if you want to pass more than one parameter to echo, the parameters must not be enclosed within parentheses.

I have highlighted the critical few words.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900