Monday, June 25, 2012

Variables in php


Variables are "stores" for storing information.this is simple definition

are you remember Mathematical equations that we study in the school

a=5     s=7     q=a+s  These letters are called variables

ii give you simple example if we have store Contains computer ,laptop , mobile phone ok

this store have name store a  which easy to say store a   or say his all Contents

there is many reasons to use Variables and i will give you some in it

how can we write  Variables in php

Variables in PHP starts with a $ sign, followed by the name of the variable example ($test)
The variable name must begin with a letter or the underscore character "_" example ($_test or $test)
A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
A variable name should not contain spaces
Variable names are case sensitive (z and Z are two different variables)

variables is  created when you give  a value to it

example

<?php
$var=55;
echo $var ;
echo"<br>";
$var1=66;
echo $var+$var1;
$var_text= "    hi every body";
echo $var_text;
?>
result
55
121hi every body


remember When we assign a text value to a variable, put quotes around the value. like   $var_text.


PHP is a Loosely Typed Language

In PHP, a variable does not need to be declared before adding a value to it.
In the example above, notice that we did not have to tell PHP which data type the variable is.
PHP automatically converts the variable to the correct data type, depending on its value.
In a strongly typed programming language, you have to declare (define) the type and name of the variable before using it.

Friday, June 22, 2012

Comments in PHP

why  we use comments

every php script have alot of code line and we want write description to every code then we use comments

comments features :

  1. you write any think and server will not read it 
  2. will not appear in the browser  
  3. will not make error in script 
how we write comments 

we use // to make a one-line comment 
we use  /* and */ to make a comment block
we use # another way to comments 

<?php
//This is a comment

/*
This is
a comment
block
*/

############this is comments
?>

Wednesday, June 20, 2012

our first php script

after we setup Apache  open this root C:\AppServ\www  an make new document  and change file extension  to  .php and open with windows notepad


and open it with notepad     OK  



A PHP script always starts with <?php and ends with ?>. A PHP script can be placed anywhere in the document.
<?php
?>  

On servers with shorthand-support, you can start a PHP script with <? and end with ?>.
For maximum compatibility, we recommend that you use the standard form (<?php) rather than the shorthand form.

that is normal to mix HTML tag  and PHP scripting code lik this example


<html>
<body>

<?php
echo "this is my first script ";
?>

</body>
</html>  



The result  will be


 this is my first script

try it and i am sure you will success 

you my ask alot of thnk about this code

let start with echo 

echo is function  to output text with PHP

print is function like echo

use any one

example with print 

<?php
print "example to see  ";
?>

ok we back to first example any text must write between  "  "  


;  Each code line in PHP must end with a semicolon. The semicolon is a separator and is used to distinguish one set of instructions from another.

if you have any question  just leave comment and i will help you

Sunday, May 27, 2012

PHP Introduction


first you must know i give you the php  learn to  you  Which  i  understand

Far from any complications

first php is simple websites Programming language to make script


PHP stands for PHP: Hypertext Preprocessor
PHP is a server-side scripting language, like ASP
PHP scripts are executed on the server
PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.)

site use php like facebook.com,  tagged

Before you continue you should have a basic understanding of the following:

HTML/XHTML
JavaScript

php is need server to translate your code  to the user browser

the browser  will read  it as html code

 your php code  >>>>>>>>>  server  >>>>>>>>>> browser  read it

to start use php you need Apache you can download from here http://www.apache.org/

and any text editor  like notepad in windows and change the file extension  to  .php