html5andphp: June 2013

Tuesday, 25 June 2013

Basic Of Php

Php

Whenever anyone is learning PHP, the most common questions that first come up are: What is PHP? And how does it work?

It is precisely these questions we will look at in this lesson. It's a big help to understand such basics related to PHP before you start developing you own PHP pages. Such basic understanding will increase the speed of learning significantly.

So, let's get started!

What is PHP?


PHP was originally an acronym for Personal Home Pages, but is now a recursive acronym for PHP: Hypertext Preprocessor.

PHP was originally developed by the Danish Greenlander Rasmus Lerdorf, and was subsequently developed as open source. PHP is not a proper web standard - but an open-source technology. PHP is neither real programming language - but PHP lets you use so-called scripting in your documents.

To describe what a PHP page is, you could say that it is a file with the extension .php that contains a combination of HTML tags and scripts that run on a web server.

Php is a widely use open source general-purpose scripting laguage that is especially suited for web development and can be embaded into html

How does PHP work?


The best way to explain how PHP works is by comparing it with standard HTML. Imagine you type the address of an HTML documens:
                                                     

Why Php?????


1. PHP runs on different operating system such as Windows, Linux, Unix, etc.
2.PHP is easy and fast to learn and runs efficiently on the server side.
3.PHP is  compatible with almost all web servers used today such as IIs, Apache, and so on .
4. PHP supports many databases such as MySQL, Oracle, PostgreSQL etc.
 5.PHP with MySQL database and Apache Server is a very good and popular combination.
 6.PHP combined with MySQL are cross-platform.
7.PHP is the widely-used, free, and efficient alternative to competitors such as Microsoft's ASP and Sun Microsystems JSP.
8.PHP is perfectly suited for Web development and can be embedded directly into the HTML code.
 9.PHP is often used together with Apache (web server) on various operating systems.
10.It can be also used with Microsoft's IIS on Windows.
11.Php is easy to learn and runs efficiently on any compatible web server.  

                                             
 Uses of PHP: 


   PHP  performs  system  functions,  i.e.  from  files  on  a  system  it  can  create,  open,  read, 
write, and close them. 
   PHP can handle forms, i.e. gather data from files, save data to a file, thru email you can 
send data, return data to the user. 
   You add, delete, modify elements within your database thru PHP. 
   Access cookies variables and set cookies. 
   Using PHP, you can restrict users to access some pages of your website. 
   It can encrypt data. 




  Characteristics of PHP 


Five important characteristics make PHP's practical nature possible: 


  1.    Simplicity 
  2.    Efficiency 
  3.    Security 
  4.    Flexibility 
  5.    Familiarity 


                     Starting tags of php


<?php ?> // standard tags
<? ?> // short tags, need short_open_tag enabled in php.ini
<% %> // asp tags, need asp_tags enabled in php.ini
<script language="php"> </script> // case insensitive

                             First Program in  PHP: 

To  get  a  feel  for  PHP,  first  start  with  simple  PHP  scripts.  Since  "welcome to php"  is  an  essential
example, first we will create a friendly little "welcome to php" script.
As mentioned earlier, PHP is embedded in HTML. That means that in amongst your normal HTML
(or XHTML if you're cutting-edge) you'll have PHP statements like this:
<html>
<head>
<title>uk</title>
<body>
   <?php echo "welcome to php";?>
</body>
</html>


                                                        OUTPUT

 welcome to php



If  you  examine  the  HTML  output  of  the  above  example,  you'll  notice  that  the  PHP  code  is  not
present  in  the  file sent  from the server to your  Web browser.  All  of the PHP present in the Web
page  is  processed  and  stripped  from  the  page;  the  only  thing  returned  to  the  client  from  the
Web server is pure HTML output.

All  PHP code must be included inside one of the  three special markup tags ate are recognised by
the PHP Parser.
<?php PHP code goes here ?>

<?    PHP code goes here ?>

<script language="php"> PHP code goes here </script>
Most common tag is the <?php...?> and we will also use same tag in our tutorial.
From the  next chapter  we will  start with  PHP  Environment  Setup on your  machine and  then we
will dig out almost all concepts related to PHP to make you comfortable with the PHP language.
PHP Environment Setup
In order to develop and run  PHP Web pages three vital components  need to be  installed on your
computer system.

 Basic Tag of php



ASP-style tags mimic the  tags  used by Active  Server  Pages  to  delineate code  blocks.  ASP-style
tags look like this:
<%...%>
To use ASP-style tags, you will need to set the configuration option in your php.ini file.
HTML script tags:
HTML script tags look like this:
<script language="PHP">...</script>
Commenting PHP Code:


  Comment 


A comment is the  portion  of  a  program  that  exists  only for  the human  reader and  stripped  out
before displaying the programs result. There are two commenting formats in PHP:
Single-line comments: They are generally used for short explanations or notes relevant to  the
local code.

                                Single  Line Comments 

<?
# This is a comment, and
# This is the second line of the comment
// This is a comment too. Each style comments only
print "An example with single line comments";
?>

Multi-lines  comments: They  are  generally  used  to  provide  pseudocode  algorithms  and  more 

detailed  explanations  when  necessary.  The  multiline  style  of  commenting  is  the  same  as  in  C.
Here are the example of multi lines comments.
<?
/* This is a comment with multiline
   Author : Mohammad Mohtashim
   Purpose: Multiline Comments Demo
   Subject: PHP
*/


For more on php visit php-tutorial

Monday, 24 June 2013

Square Pattern In Php

                          Making of square pattern using php

The given squire pattern is made from loop .There are four type of loop in php 
1. for loop
2.while loop
3. do while loop
4. foreach loop 
I will tell you about loop in next post .use this code make square pattern.

Html code

<html>
<head></head>

<body>

<br><br><br><br>
<?php
$a=6;
for ( $b = 1 ; $b <= 6 ; $b++ )
{
 echo"&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp ";
 for ( $c = 1 ; $c <= $a ; $c++ )
   { 
    echo"&nbsp ";//using for blank space
   }
    $a--;
      for ( $c = 1 ; $c <= 2*$b - 1 ; $c++ )
   {
         echo"*";
        }
      echo"<br>";
 }
 $w=1;
 for ( $d=6;$d>=1;$d-- )
{
  echo"&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp ";
for ( $e=1;$e<=$w;$e++ )
   { 
    echo"&nbsp ";
   }
    $w++;
      for ( $e=1;$e<=2*$d-1;$e++ )
   {
         echo"*";
        }
      echo"<br>";
 }
 echo"uk";
?>
</body>
</html>

Note:
Save this code using .php extention.






For more on php visit php-tutorial
                                   
                                                        square pattern
square

Arrow in php

                                        
                

                                    Making  Arrow Using Php





arrow



Html code

The given arrow pattern is made from loop .There are many for loop used to create this type of pattern.
That is nested loop . 
<!doctype html>
<html>
<head></head>
<body>
uk
<?php
for ( $b =1;$b<=9;$b++ )
{
 for ($c=1;$c<=$b;$c++)
   {
   echo"$c";
   }
echo"<br>";
 }

 for ($a=9 ;$a>=1;$a-- )
{
 for ($d=1;$d<=$a;$d++)
   {
   echo"$d";
   }
echo"<br>";
 }
?>
</body>
</html>
umar

uk

"; } for ($a=9 ;$a>=1;$a-- ) { for ($d=1;$d<=$a;$d++) { echo"$d"; } echo"
"; } ?>

Making Flage using loop in php


Loops in php

This type of flag creating using nested loops . Big deal of loops.          

flag                     


Php code



<!doctype html>
<html>
<head></head>
<body>

<?php
for ( $b =1;$b<=6;$b++ )
{
echo"&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp";
 for ($c=1;$c<=20;$c++)
   {
   echo"*";
 
   }
 
     echo"<br>";
 
 }

 for ($a=1;$a<=10;$a++)
   {
   echo"&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp";
   echo"***";
   echo"<br>";
   }

   $a=3;
for ( $b = 1 ; $b <= 4 ; $b++ )
{
 for ( $c = 1 ; $c <= $a ; $c++ )
   {
    echo"&nbsp &nbsp &nbsp";
}
    $a--;
      for ( $c = 1 ; $c <= 2*$b - 1 ; $c++ )
   {
         echo"***";
        }
      echo"<br>";
 }
 
?>
<b>uk</b>
</body>
</html>






For more on php visit php-tutorial