Tuesday, October 23, 2012

PHP Tutorial: What are PHP Variables?


Let's make it simple, variables are nothing but "containers", containers that simply hold values or information in PHP scripting.

Okay lets break it down even further, let's go back to school level, remember ALGEBRA! Yes..... where;

x=2, y=8, find whatever you like?

Similar to that, where x holds a particular value here in above example it is "2" and letter "x" will act as a variable which holds assigned value that is "2" within it.

Rules for PHP Variables Names:

1. Variables in PHP starts with a $ sign followed by the names of the variables.

2. Variables name you are going to use must begin with a LETTER or with a underscore character.

3. Variable name can only contains alpha numeric characters and underscore such as (A-z, 0-9 and _). No special character can be used while naming your variable.

4. No space can be included or left while naming.

5. It important to know that variable names are case sensitive (a and A will act as two different variables).


PHP Tutorial - Know About PHP Syntax


In earlier post I had stated that PHP is a server side web development tool hence it use to executed on server side only and then the plain HTML result is sent back to the browser.

Thing to remember -
PHP script always starts with <?php and ends with ?>. Although, if your server support shorthand support then you can start scripting with <? and end with ?>. But it is highly recommended that you should go with usual way i.e. <?php and  ?>. Also don't forget to save PHP file in .php extension.

For example:
1. First example using with echo statement;

<html>
        <body>
                <?php
                        echo "hello world!";
                ?>
        </body>
</html>

2. Second example using with print statement;
<html>
        <body>
                <?php
                        print "hello world!";
                ?>
        </body>
</html>

In above example you might have noticed that, each code line in PHP is ending with a semicolon (;). The semicolon act as an separator and is used to distinguished one set of instructions from another.
Now here we had use two different type of statements to output "Hello World" text with PHP "echo" and "print".

Difference between echo and print statement:-
There is very slight difference between two of them which is mentioned below;

1. echo is slightly faster than print. echo is marginally faster since it doesn't set a return value where as print always return 1.

2. Both print and echo take only 1 argument when used with parentless (like a function call). However, when used without parentless, echo can take several argument example: "hello", "world", "!", "repeat".



Saturday, October 20, 2012

PHP Tutorial - Where and How To Begin?


Okay the big moment has arrived, your very first step in PHP is about to began;

To get access to a web server with PHP support you can do either of two below mention things;
  • You can install Apache (or IIS) on your own server and then install PHP and supporting database like MySQL, Oracle or even ODBC.
OR
  • You can do the easy and recommend way by finding a web hosting plan with PHP and MySQL support. Although now days every web hosting providers use to provide such support.
You can download PHP, MySQL database and Apache server through internet in no time and since they all are open source programs, hence it is absolutely FREE of cost to download and run.

Follow the links to download required programs;

PHP Download        - www.php.net/downloads.php
MySQL Download    - www.mysql.com/downloads

What is PHP (Hypertext Pre-Processor)?


Hypertext Pre-Processor widely known as PHP. It is a server-side scripting (similar to Microsoft's ASP) language. PHP is a powerful tool for making dynamic and highly interactive web pages, this scripts are special commands that must be placed within web pages.

What you should already know?
If you are willing to learn PHP then it is highly recommended that you have a basis understanding of few web development languages such as;
·        HTML/XHTML
·        JavaScript
PHP is a server-side scripting language, scripts are executed on server-side. PHP can support various database such as MySQL, Informix, Oracle, ODBC, etc).

Why to use PHP?
The biggest advantage of PHP (Hypertext Pre-Processor) scripting is that it is open-source web development tool, which mean absolutely free to download and use. Many community members help this language to keep it up to current industry standard and use to update on regular basis.

It can run on different platforms or operating system such as Windows XP, Windows 7, Linux, Unix, etc. PHP is also compatible with almost all server this days for example Apache and IIS. Other than this, it is easy to learn with basic knowledge of HTML you can efficiently run it on the server.

What do PHP pages look like?
They are very similar to HTML tags, however HTML starts and ends with LESSER-THAN (<) and GREATER-THAN (>) brackets, where as PHP scripting starts with "<?php" or "<?" and usually ends with "?>", known as opening tags and closing tags respectively, between this two tag all the mambo-jumbo is done.

With PHP scripting you get some extra freedom of placement, by placement i mean you can insert scripting anywhere you like, even inside HTML tags.


Post Continued: PHP Tutorial - Where and How To Begin?