PHP Overview

How to run php projects or php file:

if you are using WAMP:

  • Put your php file in your www folder (usually in C:\wamp\www).
  • Type URL in browser localhost/your-directory-name/your-php-file-name.php

if you are using XAMPP in Windows:

  • Put your php file in your htdocs folder (usually in C:\Program Files\xampp\htdocs).
  • Type URL in browser localhost/your-directory-name/your-php-file-name.php

if your a using XAMPP in Linux(Ubuntu):

  • Put your php file in your htdocs folder (usually in /opt/lampp/htdocs).
  • Type URL in browser localhost/your-directory-name/your-php-file-name.php

 

PHP Extension:

  • The php file extension will be .php
  • PHP – Hypertext Preprocessor.

Example: myfirstphp.php, example1.pnp

  • Basic Syntax of writing php code:PHP script begins with <?php and ends with ?>
  • Your php code goes between <?php and ?>
  • Every php statements ends with “;”;

Example:

<?php

echo “My first php code”;

?>

Write the above code in a file called my-first-php-code.php and run to find the output

 

Comments in PHP:

Following are the types of comments in php

Single line comment (Using //)
Single line comment in shell syntax (Using #)
Multiline comments (Using /* comments */)

 

PHP Case Sensitivity:

PHP is a case sensitive programming language. In case of variables, keywords, class name, function name etc. are case sensitive. Therefore variable $val1 and $VAL or $Val are not the same variable in php.

 

Embed PHP with HTML:

As php is a server side scripting programming language, php can be embedded in HTML as follows

Example:

<html>

<head>

</head>

<body>

<p>Echoing from embedded php code</p>

<?php

echo ‘This is printed using php.’

?>

</body>

</html>
Check Page Rank