How To Write PHP Code? – PHP Syntax And Comments
√ How to write PHP Code?
√ What is PHP Syntax and Comments?
PHP Syntax can be merged with Plain HTML Page and it doesn’t get displayed on client side. It is executed in server and returns plain HTML page to the client. You can write any PHP logic inside the following block in your HTML page.
<?php //Your PHP Code and Logic goes here. ?>
Complete Programming Example
Step 1: Create a folder inside c:/wamp/www folder named phptutorial
Step 2: Create a page inside phptutorial folder named
Step 3: Now paste the following code in index.php page.
<!DOCTYPE html> <html> <head> <title>PHP Syntax and Comments</title> </head> <body> <h1>PHP Syntax and Comments</h1> <?php //This is PHP Comments Example /* This is PHP Comments Example */ # This is PHP Comments Example $str="Hello World"; echo $str; ?> </body> </html>
Step 4: Run this code in a web browser like Chrome, Mozilla or Internet Explorer. Open localhost/phptutorial/index.php to run this script.Output
More facts about PHP Syntax and Comments
- All the PHP page have .php extensions
- All the PHP code must be written under
<?php //Your code block ?>code block.
- There is three famous comments style inside PHP.
- // Your Comments
- /* Your Comments */
- # Your Comments
- PHP keywords, functions and classes are not case sensitive so, you can use PHP function or classes either in capital letter or small letter. For example
echo "Hello World"and
ECHO "Hello World"are same.
- PHP Variables are case sensitive so the
$sTRare the different variables.
<!DOCTYPE html> <html> <head> <title>PHP Syntax and Comments</title> </head> <body> <h1>PHP Syntax and Comments</h1> <?php //This is PHP Comments Example /* This is PHP Comments Example */ # This is PHP Comments Example $str="Hello World"; $sTR="How are you?"; echo $str; eCHo "<br />"; ECHO $sTR; ?> </body> </html>Output
How are you?
In this tutorial you learn how to and where to write PHP script in html page. You also learn how to use commenting in PHP Code. In the next chapter you will learn PHP Echo and Print function.