Showing posts with label print. Show all posts
Showing posts with label print. Show all posts

Saturday, 14 September 2013

Writing your first "Hello World" script | Chapter 1 Cont.



Firstly create a file with any random name with an .php extension & save it in the web root directory.

introduction to phpintroduction to php












 A PHP block started <?php tag & ends with ?>. There are two basic statements for showing an simple Hello World! message on the browser.

Using Print -

<?php 
 print "Hello World!";
?>

Using Echo -

<?php
echo "Hello World!";
?>


Write & save the above php code. When you run the file on your browser, it will show the expected result which is Hello World!.

introduction to php












One main thing to know before you move further is that HTML can be embedded inside php & php can be embedded inside html.


  • Using PHP inside HTML

<html>
<head>
<title>TEST</title>
</head>
<body>
<?php echo "PHP-Sec"; ?>
</body>
</html>



php hello world scriptintroduction to php



But the interesting part is when you look at the page source code, you will not find any php code but instead HTML source code. As we have read in the previous introduction chapter that php is an server side scripting language. The code is executed on the server side & the output is converted & shown as HTML on the client side. No one can view the original source code.




  • Using HTML inside PHP

<?php
echo "<html>";
echo "<head>";
echo "<title>TEST</title>";
echo "</head>";
echo "<body>";
echo "<h1>PHP-Sec</h1>";
echo "</body>";
echo "</html>";
?>


introduction to php




Now let's have get forward to the next step which is Comment Line. Comment line is used to comment out something which is ignored while the script gets executed. It doesn't effect the PHP code. The basic purpose of using comment line are
-  Writing Code Description
-  Algorithm Working
- Writing credits
and so on.