Introduction to PHP

PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.

This lesson is to explain the Introduction to PHP. Our Tutorials website’s main motto is to explain step by step PHP topics with complete examples. As you know that the importance of web development Technology now a day is rapidly expanding its strength around the world.

The PHP programming in the web is similar to C language in the windows or dos, though some differences exist. The syntax are almost the same. It can be ran on the Linux servers on the web and it can be matched with wide range of other servers and web browsers.

I would like to explain and conduct free classes on each and every lesson to help people who wants to choose their career as a PHP Developer. This PHP Tutorials website helps you lot to learn and update yourself various critical issues in your development and learning process. I wish all the best to use this PHP Tutorials online website. If you are a PHP developer just share your programs or solutions here which may help others a lot.

Let’s Get Started

To begin working with PHP you need a host for testing or running and debugging. You can buy it from the internet or register a free one. They aren’t hard to get found. Another choice is to make your computer working as a host. In this way your computer host name is ‘local host’ and you can access it, usually by typing ‘127.0.0.1’ in one web browser such as ‘Microsoft Internet Explorer’. It’s better to read html tutorial before any web programming, here we don’t spend time for it because of the wide range of our discussion. Now let’s start the tutorial!

Thanks and continue reading this PHP Tutorial.

What is PHP?

  • PHP stands for “Hypertext PreProcessor.
  • PHP is a server side scripting language that is embedded in HTML. It is used to manage dynamic content, databases, session tracking, even build entire e-commerce sites.
  • It is integrated with a number of popular databases, including MySQL, PostgreSQL, Oracle, Sybase, Informix, and Microsoft SQL Server.
  • PHP scripts are executed on the server
  • PHP is pleasingly zippy in its execution, especially when compiled as an Apache module on the Unix side. The MySQL server, once started, executes even very complex queries with huge result sets in record-setting time.
  • PHP is free to download and use
  • PHP supports a large number of major protocols such as POP3, IMAP, and LDAP. PHP4 added support for Java and distributed object architectures (COM and CORBA), making n-tier development a possibility for the first time.
  • PHP is forgiving: PHP language tries to be as forgiving as possible.
  • PHP Syntax is C-Like.
  • PHP is free to download.

PHP is an amazing and popular language!

It is powerful enough to be at the core of the biggest blogging system on the web !
It is deep enough to run the largest social network Like Facebook!
It is also easy enough to be a beginner’s first server side language!

What is a PHP File?

  • PHP files can contain text, HTML, CSS, JavaScript, and PHP code
  • PHP files have extension “.php”
  • PHP code are executed on the server, and the result is returned to the browser as plain HTML

What Can PHP Do?

  • PHP can generate dynamic page content
  • PHP can create, open, read, write, delete, and close files on the server
  • PHP can send and receive cookies
  • PHP can collect form data
  • PHP can add, delete, modify data in your database
  • PHP can encrypt data
  • PHP can be used to control user-access

With PHP you are not limited to output HTML. You can output images, PDF files, and even Flash movies. You can also output any text, such as XHTML and XML.

Why PHP ?

  • PHP runs on various platforms like Windows, Linux, Unix, Mac OS X, etc.
  • PHP is compatible with almost all servers used today (Apache, IIS, etc.)
  • PHP supports various databases like MS-Access, MySQL and SQLite etc.
  • No need to pay anything for PHP
  • PHP can be downloded directly from http://php.net website.
  • PHP syntax like basic C – language. It is easy to learn.

What we need?

Install PHP
Install a Web Server (Ex: Apache)
Install a database. (Ex: MySQL)

Useful Softwares

You can install directly any of the following software to work with all the above requirements. The softwares will reduce our work to install each and every software individually. The software is even lighter weight to install and run. See, there are various options available for PHP development.

  • WAMP
  • LAMP 
  • MAMP 
  • XAMPP 
  • APPSERV

I use Apppserv software in my example to explain all examples in our discussion.

Example:

<!DOCTYPE html>
<html>
<body>

<?php

echo “Hello”;
echo “My first PHP script”;
?>

</body>
</html>

Out Put:

Hello

My first PHP script

What distinguishes PHP from something like client-side JavaScript is that the code is executed on the server, generating HTML which is then sent to the client. The client would receive the results of running that script, but would not know what the underlying code was. You can even configure your web server to process all your HTML files with PHP, and then there’s really no way that users can tell what you have up your sleeve.

The best things in using PHP are that it is extremely simple for a newcomer, but offers many advanced features for a professional programmer. Don’t be afraid reading the long list of PHP’s features. You can jump in, in a short time, and start writing simple scripts in a few hours.

Although PHP’s development is focused on server-side scripting, you can do much more with it. Read on, and see more in the What can PHP do? Section, or go right to the introductory tutorial if you are only interested in web programming.

All About PHP Tags

The PHP code begins with <?php and ended with ?> is similar to all HTML tags because they all begin with a less than (<) symbol and end with a greater than (>) symbol.These symbols (<?php and ?>) are called PHP tags.They tell the web server where the PHP code starts and finishes. Any text between the tags is interpreted as PHP. Any text outside these tags is treated as normal HTML.The PHP tags allow you to escape from HTML.

You can choose different tag styles. Let’s look at these tags in more detail.

There are actually four different styles of PHP tags. Each of the following fragments of code is equivalent:

XML style

<?php echo ‘<p>Welcome to PHP Tags.</p>’; ?>

It is the preferred PHP tag style.The server administrator cannot turn it off, so you can guarantee it will be available on all servers, which is especially important if you are writing applications that may be used on different installations.This tag style can be used with Extensible Markup Language (XML) documents. In general, we recommend you use this tag style.

Short style

<?php echo ‘<p>Welcome to PHP Tags.</p>’; ?>

This tag style is the simplest and follows the style of a Standard Generalized Markup Language (SGML) processing instruction. You should avoid using short tags in your application, especially if it’s meant to be distributed on other servers. This is because short tags are not always supported (though I never seen any web host that don’t support it). Short tags are only available only explicitly enabled setting the short_open_tag value to On in the PHP configuration file php.ini.

SCRIPT style

<script language=’php’> echo ‘<p>Welcome to PHP Tags.</p>’; </script>

This tag style is the longest and will be familiar if you’ve used JavaScript or VBScript.You might use it if you’re using an HTML editor that gives you problems with the other tag styles.

ASP style

<% echo ‘<p>Welcome to PHP Tags.</p>’; %>

This tag style is the same as used in Active Server Pages (ASP) or ASP.NET.You an use it if you have enabled the asp_tags configuration setting.You probably have no reason to use this style of tag unless you are using an editor that is geared toward ASP or ASP.NET. Note that, by default, this tag style is disabled.

Comments in PHP

Comments are integral to programming not because they do anything but because they help you remember why you did something. The computer ignores these comments when it processes the script. Furthermore, PHP comments are never sent to the Web browser and therefore remain your secret.

You can use it to write documentation of your PHP script describing what the code should do. A comment can span only for one line or span multiple line.

PHP support three kinds of comment tags :

  1. //
    This is a one line comment
  2. #
    This is a Unix shell-style comment. It’s also a one line comment
  3. /* ….. */
    Use this multi line comment if you need to.
<?php
echo “First line <br>”; // You won’t see me in the output
// I’m a one liner comment/*
Same thing, you won’t
see this in the output file

*/
echo “The above comment spans two lines <br>”;# Hi i’m a Unix shell-style comment
# Too bad you can’t see me
echo “View the source of this file, you’ll see no comments here <br>”;
?>

Note that you can’t use HTML comment characters (<!– and –>) within PHP to comment out code. You could have PHP print those tags to the browser, but in that case you’d create a comment that appeared in the HTML source code on the client’s computer (but not in the browser window). PHP comments never make it as far as a user’s computer.

Add a Comment

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

ABOUT CODINGACE

My name is Nohman Habib and I am a web developer with over 10 years of experience, programming in Joomla, Wordpress, WHMCS, vTiger and Hybrid Apps. My plan to start codingace.com is to share my experience and expertise with others. Here my basic area of focus is to post tutorials primarily on Joomla development, HTML5, CSS3 and PHP.

Nohman Habib

CEO: codingace.com

Request a Quote