31 July 2012

MY First Program in PHP

35 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...

35 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. 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
  5. 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
  6. 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
  7. It is very informative and I enjoyed to read your blog.

    ReplyDelete
  8. Awesome data for me....thanks for sharing the instructive post...am took in some data about PHP. PHP Training Institute in Ahmedabad , PHP classes in Ahmedabad

    ReplyDelete
  9. Hi,

    Thanks for sharing a very interesting article about MY First Program in PHP. This is very useful information for online blog review readers. Keep it up such a nice posting like this.

    From,
    Maestro Infotech,
    Web Design Company Bangalore

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. Great information for me....thank for sharing the informative post...am learned the some information about php..web design company in chennai

    ReplyDelete
  12. It’s always so sweet and also full of a lot of fun for me personally and my office colleagues to search your blog a minimum of thrice in a week to see the new guidance you have got.
    Click here:
    Angularjs training in chennai

    ReplyDelete
  13. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.
    Click here:
    Microsoft Azure training in online

    ReplyDelete
  14. This is ansuperior writing service point that doesn't always sink in within the context of the classroom. In the first superior writing service paragraph you either hook the reader's interest or lose it. Of course your teacher, who's getting paid to teach you how to write an good essay, 

    click here

    Selenium Training in Chennai

    Selenium Training in Bangalore

    ReplyDelete
  15. Thanks for sharing this wonderful blog. Helpful article ! Kindly visit us @ Chocolate gift box

    ReplyDelete
  16. First this is a really Creative and Unique Article. Well, the main reason of me sharing my post here is that, We being the Digital Marketing Company In India are open for Partnerships with Mobile App Development, Website Development and Graphics related company !

    Get in touch with the Digital Marketing Services In India for more information

    ReplyDelete

  17. I like you post.It is very usfull to all.
    In this post having more usefull information and improve our knowledge.Can you share more valuable information present Technology.
    Dot Net Training in Chennai
    Selenium Testing Training in Chennai
    Software Testing Training Institute in Chennai
    Core Java Training in Chennai
    PHP Course in Chennai

    ReplyDelete
  18. Thank you for your informative post keep sharing the valuable information like this.

    Piper

    Data Cleansing Services India

    ReplyDelete
  19. Thanks for showing your interest and informative info.

    ReplyDelete
  20. Thanks for sharing such a great blog Keep posting..
    PHP Training in Gurgaon
    PHP Training institute in Gurgaon

    ReplyDelete
  21. Good Post and its informative one. Thank you for sharing this good article, it was so good to read and very useful to update my skill as updated one.

    Linux Training in Electronic City

    ReplyDelete
  22. Howdy! This blog post could not be written any better! Looking at this article reminds me of my previous roommate! He always kept preaching about this. I’ll send this post to him. Fairly certain he’s going to have a great read. Thanks for sharing!|

    ReplyDelete





  23. Site Galleria is a Web development company in Bangalore . It provides other services such as Mobile App Development Services for consumer-facing and corporate environments. We also provide Ecommerce web development services, Digital Marketing and SEO Services . We have a team of experienced SEO professionals who will understand your business and create a strategy to fulfil your commercial objectives. Site Galleria is also recognized as best Digital Marketing company in Bangalore

    ReplyDelete
  24. Attend The Data Science Courses From ExcelR. Practical Data Science Courses Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Data Science Courses.share rekaetd details.
    Ai & Artificial Intelligence Course in Chennai
    PHP Training in Chennai
    Ethical Hacking Course in Chennai Blue Prism Training in Chennai
    UiPath Training in Chennai

    ReplyDelete