Create a file named hello.php and put it in your web server's root directory (DOCUMENT_ROOT) with the following content
* DOCUMENT_ROOT in cae of xampp is "c:/xampp/htdocs". PHP programs should be saved in htdocs folder
Example #1 Our first PHP script: hello.php
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>Use your browser to access the file with your web server's URL, ending with the /hello.php file reference. When developing locally this URL will be something like http://localhost/hello.php or http://127.0.0.1/hello.php but this depends on the web server's configuration. If everything is configured correctly, this file will be parsed by PHP and the following output will be sent to your browser:
output :"Hello World"
and the html source code would look like this:
<html> <head> <title>PHP Test</title> </head> <body> <p>Hello World</p> </body> </html>
Now an Explanation of our Hello.php program
line1: opening of html tag
line 2: opening of head tag
line 3: opening and closing of title tag with a tilte to appear on tab.
line 4: opening of body tag
line 5: starts with <?php then echo opening of paragraph tag and some text and closing of paragraph tag and then closing of ?>
Note: 1)every PHP program must start with <?php must end with ?>.
2)The statements written inside the "<?php...... ?>" will be executed by php interpreter.
3)In the above example you can see echo statement echo is used to output the result, moreover a html tag can also be sent as output to the browser with echo statement.
Example : echo '<p>Hello World</p>';
line 6: closing of body tag
line 7:closing of html tag
No comments:
Post a Comment