31 July 2012

MY First Program in PHP

13 comments

first php program
After installing all the prerequisites for setting up PHP environment like installing LAMP server, installing PhpMyAdmin we are now able to start with writing our first program in php. Lets start

Step 1: If you are using Linux system, then first go to /var/www/ directory.

Step 2: Create php file called first.php.

Step 3: Using your favorite text editor, open this file and write the following code and save it.

<?php
echo "My first program in php";
?>

Step 4: Now open your browser and enter following url to execute it localhost/first.php

first program in php

Note: <?php and ?> are opening and closing tags.

Php program Using OOPs

Above method of writing program is known as procedural approach. Now OOPs concepts has been already introduced in PHP5, so lets rewrite the above program using OOPs i,e using classes.

Step 1: Make a file called class.php and write the following code and save it.

<?phps

class firstClass
{
 public function display()
 {
   echo "My first program in php!" ;
 }
}
$f1 = new firstClass() ; //creating object of the class.
$f1->display() ; //calling method  of a class.
?>

Step 2: Open browser to execute the file.


That's it. You have successfully written your first Php code using procedural approach and OOPs approach.
Enjoy :)


If You Liked This Post Please Take a Time To Share This Post

You May Also Like...

13 comments:

  1. Great information for me....thank for sharing the informative post...am learned the some information about php...PHP Web Design Company Bangalore | PHP Website Design Company in Bangalore

    ReplyDelete
  2. Best web designing company in bangalore - http://aarusys.com

    ReplyDelete
  3. I have enjoyed reading your articles. It is well written. It looks like you spend a large amount of time and effort in writing the blog. I am appreciating your effort. You can visit my site.
    Website designers in Bangalore | Website developers in Bangalore

    ReplyDelete
  4. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..
    iOS Training in Chennai
    Android Training in Chennai
    php Training in Chennai

    ReplyDelete
  5. Wonderful bloggers like yourself who would positively reply encouraged me to be more open and engaging in commenting.So know it's helpful.
    PHP Training in Chennai

    ReplyDelete
  6. Pretty section of content. I simply stumbled upon your site and in accession capital to say that I get actually loved to account your blog posts.
    PHP Training in Chennai

    ReplyDelete
  7. Wonderful bloggers like yourself who would positively reply encouraged me to be more open and engaging in commenting.So know it's helpful.
    PHP Training in Chennai

    ReplyDelete
  8. Thank you for sharing such an informative news with us. Keep on sharing Contents like this. You can also share this content on various sites like the Automation Associates LLC site.

    ReplyDelete
  9. Thank you for sharing this information. Come back again for more interesting stuff like this post. You can share this informative post in Social Media sites like the worldwide famous Facebook, the all-time favorite Twitter and the most interesting Google Plus site, business site LinkedIn and also to the Infographic site Pinterest to generate more traffic to your blog post.

    ReplyDelete
  10. I have analyzed your post. Excellent details you did here. I enjoyed reading your blog, and it is both instructional and enjoyable. Share this most interesting post in other sites like OS Business Opportunities, the innovative Asaim Japan site and also to the Jfissures site followed by Free Samples 411 and lastly to the sites like Johny Adams sites.

    ReplyDelete
  11. The post is very informative. It is a pleasure reading it. I have also bookmarked you for checking out new posts. You can also share this valuable content on other platforms such as Blogspot, the famous Wordpress site, the innovative Tumblr site and also the sites like Medium and the famous Live Journal site.

    ReplyDelete
  12. Home Interiors Designers in Bangalore

    Chetain Interiors has highly skilled and experienced Architecture crews, hence our past Portfolio talks much about our work all the way from architecting houses from scratch, to designing the interiors.

    ReplyDelete