PHP - My First PHP Program

This is a basic php embeded HTML program.

<?php
    echo "<h3>Hello This is my First PHP Program </h3>";
?>

<?php
    print ("<h3>Hello This is my First PHP Program </h3>");
?>

According to the above program you can appear Following out put

Hello This is my First PHP Program


  • echo and print statements are use to write something in the browser. Within the echo statement we can use html tags to format the text.

PHP - Comments

There are 02 comments used with PHP scripts.

  1. Single line Comment
    Single line comments can be specified by //
    Ex:

    <?php
    // This script print Hello World in the browser

         echo "Hello World"
    ?>
  2. Multiple line Comment
    Multiple Line Comment begins with "/*" and ends with */.
    Ex:

    <?php 
    /* This is a multiple line comment You can comment
    any no of lines within this block
    */

         echo "Hello World"
    ?>

PHP - How to create php files

Normally PHP script block starts with <?php and ends ?> and it can be embedded with HTML. PHP block can be placed anywhere in the document either with html tags or not.

HTML Embeded php code
<html>
  <head>
    <title>This is my First PHP Program</title>
  </head>
  <body>
    <?php
      echo "This is my First PHP Program";
    ?>
  </body>
</html>

Pure PHP Code

<?php
      echo "This is my First PHP Program";
?>

Shorthand PHP Code

Following code executed when the shorthand mood enabled in the server.

<? echo "This is my First PHP Program"; ?>

It is necessary to specify extention of the php file name as ".php" other wise php scrip does not execute.
Ex: Hello.php


PHP

Today onward I'm starting to teach all of you about the server side programming with php. I think these posts are much more interesting for you and hope you enjoy programming with php. Your comments highly appreciate.

Best Wishes,
Priyal

PHP - How to Execute Script

PHP scripts are unable to execute as normal html web pages thus php scripts are run only on the web servers. Therefore before executing the scripts, you should run your web server. All the php pages should be located inside the web server folder.

  • Through Wamp Server 
    Running wamp server and put it online before doing the execution. You can see a folder named "www" inside the wamp folder located in your C drive. PHP script pages should be located within that folder. It is better to create a folder and save all the documents there.
    PHP files cannot access with its full path like html (Ex: C:/wamp/www/php/hello.php). That www folder act as your local web server stored location and therefore you can call the above path "http://localhost/php/hello.php".
    localhost or 127.0.0.1 : this is the dns address of your web server located in your machine.
    php : php folder created in www folder.

    I think now you are familiar with storing php script pages.
  • See how to run php files with wamp server

PHP - Introduction

  • What is PHP?

    PHP is stand for PHP Hypertext Preprocessor. PHP is a widely used open source general purpose serverside scripting language for web developing and can be embeded into HTML. PHP originally created by Rasmus Lerdorf and now it is produced by PHP group. Initially it stood as Personal Home Page but now stand for this way. This is an successful free alternative to other web competitors such as Microsoft Asp. Currently php 5.5.0 version released and available from 21st March 2013.

    In this note set I'm going to discuss about php and how to execute scripts on your server.
    • PHP supports many Databases
    • PHP is an open source Software
    • PHP is a free Software
    • PHP is a server side scripting language and executed on the server

  • Why PHP
    PHP is open source solution and runs on every platform such as Windows, Linux, Unix and etc. and compatible with all web servers such as Apache, IIS & Etc

  • Before you start PHP programming needed to install php in your machine. It is better to download wampserver for windows and xamp server for linux. This includes Apache, php, Mysql and other technologies required for web programming.
  • Links for Downloads

HTML Drop Down List


  • Select tag
    This tag defines a drop down list to select chices
    Syntax:
    <select>
          <option>Choice 1</option>
          <option>Choice 2 </option>
    </select>
    • Option tag uses to define the choices of the list. This should be within the select tag.

      Ex:

      Code:
      <form>
        
      Designation:
      <select>
             <option>Mr. </option>
             <option>Mrs. </option>
             <option>Ms. </option>
             <option>Dr. </option>
             <option>Rev. </option>
             <option>Prof. </option>       <option>Other. </option></select>


      Output :
      Designation: