• Home
  • Technology
    • Ebullientech
    • Entrepreneurship
    • Video Technology
    • Cloud Computing
    • Business Analysis
  • Healthcare
    • Pharmacology
  • Thoughts
    • Food
    • General
    • Stories
    • Places
    • Workplace
    • Social Issues
    • Reviews
  • Quotes
  • Ebullientech News and Events
  • About

Kamalika's Notebook

thinking nothing...............!!

You are here: Home / Kamalika / Technology / PHP / Write your first PHP program…

Write your first PHP program…

August 19, 2014 By Kamalika 1 Comment

Step 2 – Write a PHP program

Before you begin, you need to understand the concept of ‘Document Root’. The ‘Document Root’ is the folder where you keep files for any web-based application developed using a server side scripting language like PHP, for XAMPP on Windows ‘Document Root’ location is C:\xampp\htdocs. It is different in case of a Linux server or an IIS server but those discussions are out of scope for this article.

You’ll also require a Text / HTML / PHP Editor or IDE to write PHP code that supports syntax highlighting. PSPad and Notepad++ are two good Editors available for free download and install, they are easy and simple to use for beginners as well as pros.

Create a new folder under your ‘Document Root’; name it as Bittu (replace with your own name or any name you wish to keep).

Now create your first PHP program file within Bittu folder and name it as test1.php. You can simply create one test1.txt file and rename it as test1.php or you can open a new PHP document within your PSPad or Notepad++ Editor and save it under Bittu folder as test1.php.

[php]

<?php

// Set display_errors to on for debugging purpose

ini_set(‘display_errors’, ‘1’);

echo ‘My first PHP Program to subtract one number from the other…’.'<br/>’;

$x = 50;

$y = 20;

if ($x > $y)

$sub = $x – $y;

else $sub = $y – $x;

echo ‘Result: ‘. $sub;

?>[/php]

Save the file test1.php and run on browser, type http://localhost/Bittu/test1.php in the address bar and press ENTER. You should see an output like…

My first PHP Program to subtract one number from the other…

Result: 30

<?php and ?> are open and close tags for a PHP file

Any PHP variable starts with a Dollar ($) sign

Each PHP line of code terminates with a semicolon (;)

// or # is used to comment out a line in PHP

PHP is case sensitive

echo is used to print the output

<br/> is a HTML tag for line break

Dot (.) is used for concatenation in PHP

You can learn all PHP syntaxes from PHP Manual.

W3Schools provide good tutorial for PHP basics.

Refer to W3Schools for HTML basics as well.

Go to next page for important definitions.

Pages: 1 2 3

Filed Under: PHP, Technology Tagged With: Install XAMPP on Windows, Learn PHP, PHP, PHP Coding, Write PHP Code, Write PHP Program, XAMPP

« That little girl…
How to connect to MySQL database using PHP »

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Connect with Facebook

Let’s connect…

  • Facebook
  • Instagram
  • LinkedIn
  • Twitter
  • YouTube

Hello There…

I'm Kamalika, a techpreneur & startup mentor, blogger, hobbyist photographer, Netflix & Kindle indulgent, food connoisseur, Starbucks aficionado and former Disney employee ...next

Looking for something?

Tags

All in One SEO Pack AWS Banaras Blogger Blogging Blogs Dasaswamedh Ghat Ebullientech Ebullientech Interactive LLP Facebook Facebook Developers father's day father's day wishes father's day wishes for dad fathers day love Fathers Day Special Fathers Day wishes from daughter Father’s day memories GeoTech GeoTech Informatics HipHop for PHP Kamalika Guha Roy Kashi Ganga LAMP MySQL Nabaneeta Guha Roy Online Marketing PayPal PayPal's suspension of Indian bank transactions PHP PHP & MySQL Saraswati Puja Search Engine Optimization SEO Startup The Ganges TypePad UCO HUT Varanasi Web 2.0 Web 2.0 Design Web Design Web Marketing WordPress WordPress.COM

Timeline

  • 2024 (1)
  • 2021 (3)
  • 2020 (7)
  • 2019 (4)
  • 2018 (1)
  • 2015 (6)
  • 2014 (13)
  • 2013 (9)
  • 2010 (7)
  • 2009 (2)

Topics

Copyright © 2021 · Kamalika Guha Roy, Powered by: Ebullientech